Cannot pass SESSION variables between pages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manny6677
    New Member
    • Jun 2007
    • 3

    Cannot pass SESSION variables between pages

    Trying a simple test of passing $_SESSION variables between two php pages. I don't see any data on the second page and the session id that is printed out is not the same as the first page session id of the same SESSIONSAMPLE name, which I think is the problem. When I refresh either page the session id constantly changes as well which doesn't seem right either. I have session.auto_st art set to 0 (off). Any help would be greatly appreciated. Here are the two scripts:

    [code=php]<?php

    session_name('S ESSIONSAMPLE');
    session_start() ;

    $_SESSION['user_name'] = 'chippy';
    $_SESSION['full_name'] = 'Chippy the Chipmunk';
    $_SESSION['last_visit'] = '2 weeks ago';
    $_SESSION['favourites'] = 'Books';



    print_r($_SESSI ON);
    echo "<br/>\n";
    print_r(session _id());
    echo "<br/>\n";
    print_r(session _name());
    echo "<br/>\n";
    print_r(session _get_cookie_par ams());
    echo "<br/>\n";

    ?>

    <br/>
    <br/>
    <a href="session2. php">Click Here for Next Page</a>
    <br/>


    session2.php

    <?php
    session_name('S ESSIONSAMPLE');
    session_start() ;

    //
    // show the session data as we have them thus far.
    //
    print_r($_SESSI ON);
    echo "<br/>\n";
    print_r(session _id());
    echo "<br/>\n";
    print_r(session _name());
    echo "<br/>\n";
    print_r(session _get_cookie_par ams());
    echo "<br/>\n";
    ?>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Manny.

    What happens if you remove the session_name() calls?

    You can also set session.name in your php.ini file.

    Comment

    • manny6677
      New Member
      • Jun 2007
      • 3

      #3
      Tried it without the session_name calls and get the same results except I now see the default PHPSESSID session name displayed.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Manny.

        Ok, I'm curious. If you echo session_id() on each page, do you get the same result?

        Comment

        • manny6677
          New Member
          • Jun 2007
          • 3

          #5
          Originally posted by pbmods
          Heya, Manny.

          Ok, I'm curious. If you echo session_id() on each page, do you get the same result?



          Session ID is different on both pages.
          OUTPUT from page1:

          Array ( [user_name] => chippy [full_name] => Chippy the Chipmunk [last_visit] => 2 weeks ago [favourites] => Books )
          32ohq5adgif60vp j60aq9lrrh0
          PHPSESSID
          Array ( [lifetime] => 0 [path] => \ [domain] => [secure] => [httponly] => )


          OUTPUT from page 2:

          Array ( )
          24lhatmjlq3jt63 sbte6a2i1t0
          PHPSESSID
          Array ( [lifetime] => 0 [path] => \ [domain] => [secure] => [httponly] => )

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            Is this online for others to try Considering your sessions use cookies, I'm thinking you may have cookies turned off on your browser, which would cause the client to be unaware of it's session id.

            Any chance that that's the case?

            Comment

            Working...