SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session_id not being pulled from cookie

    Hi there,

    I'm calling session_start(); as soon as my page loads but when I print out my session array it's empty and the reason seems to be that the php session_id listed is not the same as the one stored in my cookie.

    I'm not destroying the session anywhere.

    Is there any way to get session_start to force getting the id from the cookie stored in the browser? I've verified that that ID is correct.

    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I'm seeing that this thread has gotten quite a few views but no one has written anything. Can you tell me if it's a dumb question?

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    So..what code are you using to write the cookie out?

  4. #4
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hy,
    maybe you can get only the ID of the current session, not from a cookie, like in the next example;
    PHP Code:
    <?php
    session_start
    ();

    echo 
    '<br /> The ID of the current session is: 'session_id();
    ?>

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    session_start
    ();

    $session_id session_id();

    $cookie_session_id $_COOKIE['PHPSESSID'];

    if ( 
    $session_id === $cookie_session_id ) {
        echo 
    'Session ID\'s Match!';
    } else {
        echo 
    'Session ID\'s Don\'t Match!';
    }

    ?>
    Try running this code, does it report the session IDs to match?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the feedback guys. I'm giving this a whirl now!

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess what? It was that I'd two sites referenced. One with www and one without. Argh!!! So frustrating. :-) Thanks for the responses guys.


Tags for this Thread

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
  •