Session_Start() Doesn't Work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Virgil Green

    #16
    Re: Session_Start() Doesn't Work

    "Chris Allen" <c.allen@nospam .co.uk> wrote in message
    news:c6u37a$mpg $1@titan.btinte rnet.com...[color=blue]
    > Hey Guess What !!???
    >
    > I removed PHP and Apache and upgraded to Apache 2 and upgraded to PHP[/color]
    4.3.6[color=blue]
    > and the same f*%#***ng thing is still happening!!
    > It's got to be something to do with Windows.[/color]

    I do believe this is the first time you've mentioned you were using Windows.
    Fix your session.save_pa th to point to a valid directory. you have it set to
    /tmp.... a *nix setting. You need to point it to a valid directory.

    - Virgil


    Comment

    • Chris Allen

      #17
      Re: Session_Start() Doesn't Work

      BINGO!!!!

      Thanks a million Virgil!!


      "Virgil Green" <vjg@obsydian.c om> wrote in message
      news:z8xkc.2331 2$023.7799@news svr22.news.prod igy.com...[color=blue]
      > "Chris Allen" <c.allen@nospam .co.uk> wrote in message
      > news:c6u37a$mpg $1@titan.btinte rnet.com...[color=green]
      > > Hey Guess What !!???
      > >
      > > I removed PHP and Apache and upgraded to Apache 2 and upgraded to PHP[/color]
      > 4.3.6[color=green]
      > > and the same f*%#***ng thing is still happening!!
      > > It's got to be something to do with Windows.[/color]
      >
      > I do believe this is the first time you've mentioned you were using[/color]
      Windows.[color=blue]
      > Fix your session.save_pa th to point to a valid directory. you have it set[/color]
      to[color=blue]
      > /tmp.... a *nix setting. You need to point it to a valid directory.
      >
      > - Virgil
      >
      >[/color]


      Comment

      • Phil Powell

        #18
        Re: Session_Start() Doesn't Work

        I got it to retain $_SESSION['sql'], however, I can retain
        $_SESSION['hidden'] but I can't seem to re-retrieve it. Consider this
        code:



        PHP:
        --------------------------------------------------------------------------------

        class SearchView extends View {

        function SearchView() {} // CONSTRUCTOR

        function &retainFormElem ents(&$html) { // STATIC HTML METHOD
        $global $_GET, $_POST;
        if ((!is_array($_P OST) || @sizeof(array_v alues($_POST)) == 0) &&
        $_SESSION['hidden']) {
        $html .= $_SESSION['hidden'];
        } else {
        $collection = ($_POST && is_array($_POST ) &&
        @sizeof(array_v alues($_POST)) > 0) ? $_POST : $_GET;
        foreach ($collection as $key => $val) {
        if (!is_array($val )) {
        $hiddenHTMLReta iner .= "<input type=\"hidden\" name=\"$key\"
        value=\"$val\"> \n";
        $html .= $hiddenHTMLReta iner;
        } else {
        foreach ($val as $innerKey => $indivVal) {
        if ($indivVal) {
        $hiddenHTMLReta iner .= "<input type=\"hidden\" name=\"${key}[";
        if (!is_numeric($i nnerKey)) $hiddenHTMLReta iner .= $innerKey;
        $hiddenHTMLReta iner .= "]\" value=\"$indivV al\">\n";
        $html .= $hiddenHTMLReta iner;
        }
        }
        }
        }
        $_SESSION['hidden'] = $hiddenHTMLReta iner;
        }
        return $html;
        }

        }

        --------------------------------------------------------------------------------



        This class method is called from the class-level scope in another
        class method:


        PHP:
        --------------------------------------------------------------------------------

        class SearchPerformer extends DBActionPerform er {

        function SearchPerformer () {} // CONSTRUCTOR

        function &displayResults () { // STATIC HTML METHOD
        // ADD STUFF to $html
        $html = SearchView::ret ainFormElements ($html); // WORKS EXCEPT FOR
        SESSION
        // ADD MORE STUFF TO $html
        return $html;
        }

        function doSearch() { // VOID METHOD
        $sql = "select * from blah";
        $_SESSION['sql'] = $sql;
        }

        }

        --------------------------------------------------------------------------------



        This is actually a dumbed-down version of my actual code except for
        retainFormEleme nts() method. I have a routine where I am doing search
        querying and returning results. Requirement (this is WORK BTW) is to
        allow for modification of the existing search query as well as sorting
        the existing query.

        The only way I could figure to do both successfully is to save the
        $sql statement into one $_SESSION variable (when you sort so that you
        have your pre-built SQL all over again without having to rebuild it
        from scratch) and store the $_POST collection variables from the form
        into another $_SESSION variable as an HTML <hidden> element string
        block (so when you click the links to sort the search results, though
        $_POST is gone your stuff is still there if you need to modify).

        However, here's my problem: While $_SESSION['sql'] exists,
        $_SESSION['hidden'] does not. Though both are set, $_SESSION['hidden']
        vanishes while $_SESSION['sql'] persists.

        I don't think it is as simple as a manual issue. I'm totally stuck on
        this, still! I have only one main script, "index.php" , with
        "session_start( )" at the very top of the script, using PHP 4.3.2 with
        register globals off and all other default settings, server is Linux
        Red Hat 7.3.

        Thanx
        Phil

        Javier_ <javier@yeahrig ht.com> wrote in message news:<sc0c80p4t 6d6rh7nikpo566g 2dlhrvtpe2@4ax. com>...[color=blue]
        > Chris,
        >
        > I ran across the same problem a couple of weeks ago. Some hosting
        > companies require special magic lines of code and incantations :) (I
        > don't know if you are using a hosting company but...) After much
        > searching on my hosting company's support site I found that not only
        > is it required to have the Session_Start() function at the top of
        > every page but additionally they required session_save_pa th() to be
        > explicity set as well at the top of every page. See below.
        >
        > <?php
        > session_save_pa th("/some/path/with/permissions/for/your/account");
        > Session_Start() ;
        >
        > $_SESSION['user']=$username;
        >
        > ?>
        >
        > It worked for me.
        >
        > There is also a function that will echo out the current
        > session_save_pa th if you're curious but I couldn't find it again.
        >
        > buena suerte! my two cents.
        >
        > Javier
        > aed7@deadspam.h otmail.com
        >
        >
        >
        >
        > On Mon, 19 Apr 2004 21:35:42 +0000 (UTC), "Chris Allen"
        > <c.allen@nospam .co.uk> wrote:
        >[color=green]
        > >Hi
        > >
        > >I'm new to PHP and I'm trying to create a Login Form. Once the user has
        > >logged in then he shouldn't have to log in again. The trouble is I'm getting
        > >a new session ID between every page and so it doesn't recognise the user.
        > >I've used Session_Start() which I thought was meant to maintain the session
        > >variables between pages but it doesn't do work.
        > >
        > >Any ideas or FAQ's?
        > >
        > >Thanks
        > >Chris
        > >[/color][/color]

        Comment

        • Phil Powell

          #19
          Re: Session_Start() Doesn't Work

          Very first lines of index.php:

          [PHP]
          session_start() ; // USED FOR ANY STORED SESSION VARIABLES (ONLY HAS
          TO BE SET HERE)
          echo "PHPSESSID = $PHPSESSID<P>";
          echo "SESSION the moment you first enter this script of $PHP_SELF is:
          "; print_r(array_k eys($_SESSION)) ; echo'<P>';
          [/PHP]

          This is what you see the moment you first go into index.php and have
          not yet submitted a search query:

          PHPSESSID = a964d0d6683757c afbe5576737ea5b f9

          SESSION the moment you first enter this script of
          /image_catalog/index.php is: Array ( [0] => search [1] => sql )
          Ok, now you submitted a search query. You entered some form stuff and
          submitted. You're now at the search results page (which is also
          "index.php" ); this is what you see:

          PHPSESSID = a964d0d6683757c afbe5576737ea5b f9

          SESSION the moment you first enter this script of
          /image_catalog/index.php is: Array ( [0] => search [1] => sql )

          GET: Array ( )

          POST: Array ( [0] => image_name [1] => allAlbums [2] => album [3] =>
          boolword [4] => keywords [5] => persons [6] => events [7] => image_alt
          [8] => image_creation_ start_month [9] => image_creation_ start_day [10]
          => image_creation_ start_year [11] => image_creation_ end_month [12] =>
          image_creation_ end_day [13] => image_creation_ end_year [14] =>
          image_location_ city [15] => image_location_ state [16] =>
          image_location_ country [17] => sortBy [18] => search [19] =>
          isFromSearch [20] => section )

          SESSION: Array ( [0] => search [1] => sql )

          PHPSESSID = a964d0d6683757c afbe5576737ea5b f9

          SESSION after setting it is: Array ( [0] => search [1] => sql [2] =>
          hidden )
          (note: to save space and sensitive info I am not doing:
          [PHP]print_r($_POST) ;[/PHP] but instead I'm using
          [PHP]print_r(array_k eys($_POST));[/PHP], and the same with $_GET)

          $_SESSION['sql'] is set via an instance of SearchPerformer object that
          runs the generateSearchS QL() method:

          [PHP]
          class SearchPerformer extends DBActionPerform er {

          function SearchPerformer () { // CONSTRUCTOR
          $this->doSearch(); // THIS METHOD RUNS generateSearchS QL()
          }

          function &displayResults () { // STATIC HTML STRING METHOD
          $html = SearchView::ret ainFormElements ($html); // SEE BELOW FOR
          CODE DETAIL
          // DO MORE STUFF TO $html
          return $html;
          }

          function generateSearchS QL() { // SQL STRING METHOD
          // BUILD $sql HERE WITH STUFF
          $_SESSION['sql'] = $sql;
          // DO MORE STUFF
          return $sql;
          }

          }

          $performer =& new SearchPerformer (); // CONSTRUCTOR
          [/PHP]

          So everything is fine so far; I have $_SESSION['sql'] and I even have
          $_SESSION['hidden'] which is set via the displayResults( ) method in
          the SearchPerformer object, it running this class method (class
          SearchView is *NOT* instantiated here!!!):

          [PHP]
          class SearchView extends View {

          function SearchView() {} // CONSTRUCTOR (you will be instantiating
          SearchView objects elsewhere, just not in SearchPerformer 's methods)

          function &retainFormElem ents(&$html) { // STATIC HTML METHOD
          print_r("<P>GET : "); print_r(array_k eys($_GET));
          print_r("<P>POS T: "); print_r(array_k eys($_POST));
          print_r("<P>SES SION: "); print_r(array_k eys($_SESSION)) ;
          print_r("<P>");
          if ((!is_array($_P OST) || @sizeof(array_v alues($_POST)) == 0) &&
          $_SESSION['hidden']) {
          $html .= $_SESSION['hidden'];
          } else {
          /*--------------------------------------------------------------------------------------------------------------------
          Set $collection to either $_POST (if form post variables exist in
          $_POST) or default to $_GET
          to parse through either/or and produce HTML hidden elements in
          either case
          ---------------------------------------------------------------------------------------------------------------------*/
          $collection = ($_POST && is_array($_POST ) &&
          @sizeof(array_v alues($_POST)) > 0) ? $_POST : $_GET;
          foreach ($collection as $key => $val) {
          if (!is_array($val )) {
          $hiddenHTMLReta iner .= "<input type=\"hidden\" name=\"$key\"
          value=\"$val\"> \n";
          $html .= "<input type=\"hidden\" name=\"$key\"
          value=\"$val\"> \n"; // ADD FROM QS TO PASS BACK
          } else {
          foreach ($val as $innerKey => $indivVal) {
          if ($indivVal) {
          $hiddenHTMLReta iner .= "<input type=\"hidden\" name=\"${key}[";
          $html .= "<input type=\"hidden\" name=\"${key}[";
          if (!is_numeric($i nnerKey)) $html .= $innerKey; // NUMERICAL
          KEYS DO NOT NEED TO BE PLACED INTO HTML ARRAY-FORMATTABLE FORM
          ELEMENTS
          if (!is_numeric($i nnerKey)) $hiddenHTMLReta iner .= $innerKey;
          $html .= "]\" value=\"$indivV al\">\n"; // PUT IN INDIVIDUAL
          ARRAY ELEMENTS
          $hiddenHTMLReta iner .= "]\" value=\"$indivV al\">\n";
          }
          }
          }
          }
          $_SESSION['hidden'] = $hiddenHTMLReta iner;
          global $PHPSESSID;
          print_r("PHPSES SID = "); print_r($PHPSES SID); print_r("<P>");
          print_r('SESSIO N after setting it is: ');
          print_r(array_k eys($_SESSION)) ;
          }
          return $html;
          }

          }
          [/PHP]
          Now, in the search results page I click a link to sort my results.
          The link takes me back to, you guessed it, index.php (in fact, every
          single portion of my application literally has only one address:
          "index.php" and nowhere else). The moment I do that, this is what I
          see:

          PHPSESSID = a964d0d6683757c afbe5576737ea5b f9

          SESSION the moment you first enter this script of
          /mu-spin/image_catalog/index.php is: Array ( [0] => search [1] => sql
          )

          GET: Array ( [0] => section [1] => search [2] => isSort [3] => sortBy
          )

          POST: Array ( )

          SESSION: Array ( [0] => search [1] => sql )

          PHPSESSID = a964d0d6683757c afbe5576737ea5b f9

          SESSION after setting it is: Array ( [0] => search [1] => sql [2] =>
          hidden )
          This is totally wrong!!! The $_SESSION['hidden'] variable is gone!!!
          It is, in fact, erroneously RESET once again (with the wrong values),
          whereas it was supposed to have been retained within $_SESSION
          superglobal array, yet it is not.

          I hope this makes it a bit more clear as to what is literally going
          on.

          Synopsis:

          1) I go to index.php
          2) I see $_SESSION
          3) I submit form elements
          4) I see $_SESSION
          5) I add $_SESSION['sql'] in generateSearchS QL() method
          6) I add $_SESSION['hidden'] in SearchView::ret ainFormElements ()
          method
          7) I see $_SESSION with both elements
          8) I click a link to go back to index.php
          9) I see $_SESSION.. with just 'sql' and NOT 'hidden'
          10) I tear my hair out, what little I have left!

          Phil

          Comment

          • Phil Powell

            #20
            Re: Session_Start() Doesn't Work

            Never mind, I got it!! It was a stray "global $_SESSION" in another
            class method altogether!

            Phil

            soazine@erols.c om (Phil Powell) wrote in message news:<1cdca2a7. 0404301510.2de7 8104@posting.go ogle.com>...[color=blue]
            > I got it to retain $_SESSION['sql'], however, I can retain
            > $_SESSION['hidden'] but I can't seem to re-retrieve it. Consider this
            > code:
            >
            >
            >
            > PHP:
            > --------------------------------------------------------------------------------
            >
            > class SearchView extends View {
            >
            > function SearchView() {} // CONSTRUCTOR
            >
            > function &retainFormElem ents(&$html) { // STATIC HTML METHOD
            > $global $_GET, $_POST;
            > if ((!is_array($_P OST) || @sizeof(array_v alues($_POST)) == 0) &&
            > $_SESSION['hidden']) {
            > $html .= $_SESSION['hidden'];
            > } else {
            > $collection = ($_POST && is_array($_POST ) &&
            > @sizeof(array_v alues($_POST)) > 0) ? $_POST : $_GET;
            > foreach ($collection as $key => $val) {
            > if (!is_array($val )) {
            > $hiddenHTMLReta iner .= "<input type=\"hidden\" name=\"$key\"
            > value=\"$val\"> \n";
            > $html .= $hiddenHTMLReta iner;
            > } else {
            > foreach ($val as $innerKey => $indivVal) {
            > if ($indivVal) {
            > $hiddenHTMLReta iner .= "<input type=\"hidden\" name=\"${key}[";
            > if (!is_numeric($i nnerKey)) $hiddenHTMLReta iner .= $innerKey;
            > $hiddenHTMLReta iner .= "]\" value=\"$indivV al\">\n";
            > $html .= $hiddenHTMLReta iner;
            > }
            > }
            > }
            > }
            > $_SESSION['hidden'] = $hiddenHTMLReta iner;
            > }
            > return $html;
            > }
            >
            > }
            >
            > --------------------------------------------------------------------------------
            >
            >
            >
            > This class method is called from the class-level scope in another
            > class method:
            >
            >
            > PHP:
            > --------------------------------------------------------------------------------
            >
            > class SearchPerformer extends DBActionPerform er {
            >
            > function SearchPerformer () {} // CONSTRUCTOR
            >
            > function &displayResults () { // STATIC HTML METHOD
            > // ADD STUFF to $html
            > $html = SearchView::ret ainFormElements ($html); // WORKS EXCEPT FOR
            > SESSION
            > // ADD MORE STUFF TO $html
            > return $html;
            > }
            >
            > function doSearch() { // VOID METHOD
            > $sql = "select * from blah";
            > $_SESSION['sql'] = $sql;
            > }
            >
            > }
            >
            > --------------------------------------------------------------------------------
            >
            >
            >
            > This is actually a dumbed-down version of my actual code except for
            > retainFormEleme nts() method. I have a routine where I am doing search
            > querying and returning results. Requirement (this is WORK BTW) is to
            > allow for modification of the existing search query as well as sorting
            > the existing query.
            >
            > The only way I could figure to do both successfully is to save the
            > $sql statement into one $_SESSION variable (when you sort so that you
            > have your pre-built SQL all over again without having to rebuild it
            > from scratch) and store the $_POST collection variables from the form
            > into another $_SESSION variable as an HTML <hidden> element string
            > block (so when you click the links to sort the search results, though
            > $_POST is gone your stuff is still there if you need to modify).
            >
            > However, here's my problem: While $_SESSION['sql'] exists,
            > $_SESSION['hidden'] does not. Though both are set, $_SESSION['hidden']
            > vanishes while $_SESSION['sql'] persists.
            >
            > I don't think it is as simple as a manual issue. I'm totally stuck on
            > this, still! I have only one main script, "index.php" , with
            > "session_start( )" at the very top of the script, using PHP 4.3.2 with
            > register globals off and all other default settings, server is Linux
            > Red Hat 7.3.
            >
            > Thanx
            > Phil
            >
            > Javier_ <javier@yeahrig ht.com> wrote in message news:<sc0c80p4t 6d6rh7nikpo566g 2dlhrvtpe2@4ax. com>...[color=green]
            > > Chris,
            > >
            > > I ran across the same problem a couple of weeks ago. Some hosting
            > > companies require special magic lines of code and incantations :) (I
            > > don't know if you are using a hosting company but...) After much
            > > searching on my hosting company's support site I found that not only
            > > is it required to have the Session_Start() function at the top of
            > > every page but additionally they required session_save_pa th() to be
            > > explicity set as well at the top of every page. See below.
            > >
            > > <?php
            > > session_save_pa th("/some/path/with/permissions/for/your/account");
            > > Session_Start() ;
            > >
            > > $_SESSION['user']=$username;
            > >
            > > ?>
            > >
            > > It worked for me.
            > >
            > > There is also a function that will echo out the current
            > > session_save_pa th if you're curious but I couldn't find it again.
            > >
            > > buena suerte! my two cents.
            > >
            > > Javier
            > > aed7@deadspam.h otmail.com
            > >
            > >
            > >
            > >
            > > On Mon, 19 Apr 2004 21:35:42 +0000 (UTC), "Chris Allen"
            > > <c.allen@nospam .co.uk> wrote:
            > >[color=darkred]
            > > >Hi
            > > >
            > > >I'm new to PHP and I'm trying to create a Login Form. Once the user has
            > > >logged in then he shouldn't have to log in again. The trouble is I'm getting
            > > >a new session ID between every page and so it doesn't recognise the user.
            > > >I've used Session_Start() which I thought was meant to maintain the session
            > > >variables between pages but it doesn't do work.
            > > >
            > > >Any ideas or FAQ's?
            > > >
            > > >Thanks
            > > >Chris
            > > >[/color][/color][/color]

            Comment

            Working...