SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: session recall

  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Madison, WI
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session recall

    WinNT, Apache, PHP4

    i have a page that creates session values as follows:

    ...
    session_start();
    session_register("nickname");
    $HTTP_SESSION_VARS["nickname"] = "jimmy crack corn";

    // displays "jimmy crack corn"
    echo $HTTP_SESSION_VARS["nickname"];
    ...

    then i navigate to another page that should recognize the session history and does the following:

    session_start();

    // try to do something with "nickname"
    $local = $HTTP_SESSION_VARS["nickname"]

    when i try to reference the nickname variable i always get an "Undefined index: nickname" error, even though session_is_registered("nickname") always returns true!

    am i missing something obvious?

    -matt
    Matt Stephenson
    msteph@chorus.net

  2. #2
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Madison, WI
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is some more information:

    under RedHat 7.1 the variables appear to be registered but the values are empty. session_is_registered("xxx") returns true but $HTTP_SESSION_VARS["xxx"] is the empty string (no error messages).

    dumping out the session IDs shows that they are the same between the first page and the second. peeking at the session file shows this:

    !xxx|

    but i'm not sure what should be in there. no values anywhere, though. every example i've seen has the same steps so i can only imagine that there is something very simple that i'm missing.
    Matt Stephenson
    msteph@chorus.net

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think your main problem is when you assign the value to nickname, it hsould work like this

    PHP Code:
    session_start(); 
    session_register("nickname"); 
    $nickname "jimmy crack corn"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Madison, WI
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it is my understanding that all session variables are available via the global $HTTP_SESSION_VARS variable. if the register_globals flag is set in the php.ini file then you are right and $nickname should be available.

    incidentally, $nickname gave me the same results.

    -matt
    Matt Stephenson
    msteph@chorus.net

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I think the problem was trying to assign a value straight into the $HTTP_SESSION_VARS; With my method after assigning the value it was available to me both through straight $nickname and through $HTTP_SESSION_VARS['nickname']. So here is the code I tried.

    test1.php
    PHP Code:
    <?php
    session_start
    (); 
    session_register("nickname"); 

    //Incidentally this did not work for me
    $HTTP_SESSION_VARS['nickname'] = "jimmy crack corn"


    //This did
    $nickname "jimmy crack corn"

    // displays "jimmy crack corn" 
    echo $HTTP_SESSION_VARS['nickname']; 
    echo 
    $nickname

    ?>
    <br>
    <a href="test2.php">test2</a>

    test2.php
    PHP Code:
    <?php
    session_start
    (); 

    // try to do something with "nickname" 
    $local $HTTP_SESSION_VARS['nickname']; 

    print 
    $HTTP_SESSION_VARS['nickname']; //prints jimmy crack corn
    print $local//prints jimmy crack corn
    ?>
    <br>
    <a href="test1.php">test1</a>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Madison, WI
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    very interesting, it is the assignment that was screwing it up. the sample code in the "sessions" section of the documentation is not correct then. it says you can do this:

    session_register("count");
    $HTTP_SESSION_VARS["count"]++;

    i did just that and the value was always empty. it also states that "...if track_vars and register_globals are enabled then the globals variables and the $HTTP_SESSION_VARS entries will reference the same variables".

    anyway - thanks much for the insight!

    -matt
    Matt Stephenson
    msteph@chorus.net

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll do some more digging, cause it does seem very odd.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Member
    Join Date
    Jul 2001
    Location
    Madison, WI
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for those that are interested, here is a follow-up.

    i discovered that with 'register_globals = On' (see php.ini) i was unable to set a new session variable using the $HTTP_SESSION_VARS entry. it appeared to work on the initial page but the values never made it to the session history. in other words, with register_globals on you MUST set variables via the globals, at least initially. i have not confirmed that this is true on subsequent pages.

    with 'register_globals = Off' everything i was trying to do worked as i expected - meaning i could call session_register('myvar') and then do something like $HTTP_SESSION_VARS['myvar'] = "myvar is cool" and the variable would get into the session history.

    -matt
    Matt Stephenson
    msteph@chorus.net

  9. #9
    SitePoint Member djrob's Avatar
    Join Date
    Sep 2000
    Location
    Melbourne
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTTP_SESSION_VARS

    Hey Guys,
    This is EXACTLY what is happening to me!!! (I'm not an idiot - )
    register_globals is set "On" and PHP is version 4.0.3, so track_vars on On by default.
    I can register a squillion bloody variables, but not one will follow through to the next page - I keep getting my "not logged on" page, and if I do a variable dump, HTTP_SESSION_VARS is empty, no matter what.
    Question is, what can I do about it other than ask my server admin to reconfigure the .ini file? If I declare $niickname to be global at the top of the file, only then will test2.php print out "jimmy crack corn". Why is it like this?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •