SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session not persisting across pages desite session_start()

    I inherited an web app that uses session. The admin logs in. He clicks a menu item. I put echo's to check what's going on. When he changes pages, the session is emply, despite there being session_start(); at the beginning of page pages before any output.

    Any ideas?
    Last edited by WebDevGuy; Jan 21, 2009 at 10:34.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check if the browser is sending back a cookie with the session id.

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after session_start() I am print_r($_SESSION) which displays nothing in the session.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check your cookies in your browser
    check if php was sent cookie in $_COOKIE

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    browser accepts cookies fine. it's happening on other user as well.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    last time ill say it, check $_COOKIE

  7. #7
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added print_r($_COOKIE) on the page linked from the index page, clicked it, it sends me back to log in but from the event page and displays:
    Array ( [PHPSESSID] => b9f2ea342711fe7e8211c9621b81b7c5 [__utmc] => 81026693 [__utma] => 81026693.1181589464.1232545892.1232555311.1232559224.3 [__utmz] => 81026693.1232545892.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none) [__utmb] => 81026693 )

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure the session id matches the id sent on the page where the session vars are set. If these pages are on different subdomains, they may very well be different id's, and that would be your problem. These are all different:

    example.com
    www.example.com
    foo.example.com

  9. #9
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks. They are all on the same domain - no subdomains.

    Now you understand why I am so frustrated. I've been doing this a while and can not find the issue.

    Thanks.

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd like to help you, but you keep ignoring parts of my posts. If you need clarification, ask. But I refuse to have to keep telling you to do something.

  11. #11
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put:
    print_r($_COOKIE);
    at the top of every page. It display the same info for every page:
    Array ( [PHPSESSID] => b9f2ea342711fe7e8211c9621b81b7c5 [__utmc] => 81026693 [__utma] => 81026693.1181589464.1232545892.1232555311.1232559224.3 [__utmz] => 81026693.1232545892.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none) [__utmb] => 81026693 )


    and I have checked that against what the cookie stored on my machine.

  12. #12
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does this increment when refreshed?
    PHP Code:
    <?php
    session_start
    ();
    echo 
    $_SESSION['i']++;

  13. #13
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    session_start();
    echo 
    "<pre>";print_r($_COOKIE);
    echo 
    $_SESSION['i']++;
    print_r($_COOKIE);
    echo 
    "</pre>"
    renders:
    Array
    (
    [PHPSESSID] => b9f2ea342711fe7e8211c9621b81b7c5
    [__utmc] => 81026693
    [__utma] => 81026693.1181589464.1232545892.1232559224.1232575708.4
    [__utmz] => 81026693.1232545892.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)
    [__utmb] => 81026693
    )
    7Array
    (
    [PHPSESSID] => b9f2ea342711fe7e8211c9621b81b7c5
    [__utmc] => 81026693
    [__utma] => 81026693.1181589464.1232545892.1232559224.1232575708.4
    [__utmz] => 81026693.1232545892.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)
    [__utmb] => 81026693
    Notice the 7 above, it increments with every refresh.

  14. #14
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like you have an issue in the code which sets session variables upon login. Post it.

  15. #15
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I rewrote the authentication and it fixed the issue.

    Thanks for your help and time!!


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
  •