Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Using session variables

  1. #11
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    session_id() will return the id that PHP is currently using to keep track of its session.

  2. #12
    Join Date
    Dec 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    The same way you do when a browser sends it: with session_start().
    Just to make sure I understand, when the applet submits the session id (which it does as an http request) I can do the following to active the session?

    PHP Code:
    $sessionId $_POST["sessionId"]; // php script receives the session id
    session_start(); // starts session
    session_id $sessionId// set the session id, so that previously set session variables can be used 
    If any of the above is wrong, please let me know. Thanks.

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, of course not. session_id() is a function, not a variable; all variables in PHP start with $.

    There's a magic request variable that PHP will automatically pick up and use as the session ID. By default, it's called PHPSESSID. You can set the current session ID by calling session_id($newid);, e.g. session_id($_POST['sessionId']);, but it's easier just to use the default variable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Dec 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    No, of course not. session_id() is a function, not a variable; all variables in PHP start with $.
    That was a mental lapse; I was looking at java and javascript code right before my post. You're absolutely right, as session_id is a function I'd have to send the posted session id ($_POST[sessionId]) as an argument.

    Quote Originally Posted by Twey View Post
    There's a magic request variable that PHP will automatically pick up and use as the session ID. By default, it's called PHPSESSID. You can set the current session ID by calling session_id($newid);, e.g. session_id($_POST['sessionId']);, but it's easier just to use the default variable.
    Thanks for the clarification; I was concerned that by setting the session id I might "overwrite" the previously set session rather than invoking it.

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
  •