Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: Stored Sessions Data Not Found

  1. #11
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    Nile,

    This is just an update. I have more work to do on your much appreciated suggestions. I missed your earlier post. Thank you for bring it to my attention. And thank you for your continued interest in this problem.

    I use sessions on this server regularly. Additionally, the duration from setting the session index to trying to retrieve it on this site is typically just a second or so, so timing out I think we can rule out.

    No, I would not expect anyone here to examine thousands of lines of code. So I do try to distill the problem. That is why I excerpted the page code. What I deleted were simply many many entries of the array. The PHP logic and syntax were preserved. It is a bit more than a sliver. Let me see how much more I can pare it down and still create the problem.

    I'll be back with more info, though possibly not today.

    A.

  2. #12
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Reproducing the code isn't cutting it down. It's making another scenario completely that I can use lightweight and test on my own. What you provided is untestable. With that though, I'll be awaiting your next reply with the information -- maybe that'll shed light on what's going on here.

    Edit: After searching Google for setting sessions then redirecting, I'm finding other users that have had the same problems as you (I've tried to reproduce but it all works okay). Below I'll list a few solutions I've seen.

    • Use session_write_close() before or after the header redirect. I've see it both ways online, and I'm not sure which way is best/ideal, but try the following (uncomment and see which one works... if both works, choose your pick):
      PHP Code:
      $_SESSION'foo' ] = $bar;

      // session_write_close();
      header'Location: ...' );
      // session_write_close(); 
    • I've seen people using exit(); and claim that putting it after the redirect fixes this issue:
      PHP Code:
      $_SESSION'foo' ] = $bar;

      header'Location: ...' );
      exit(); 
    • I've also seen someone try and set the PHPSESSID cookie in the header, but it looks like your PHPSESSID cookie is definitely setting. Anyways, give it a go:
      PHP Code:
      $_SESSION'foo' ] = $bar;

      header'Set-Cookie: PHPSESSID=' session_id() . '; path=/' );
      header'Location: ...' ); 


    If none of these work, like I previously mentioned, I did try and reproduce this issue on another example page here, though it works like expected. You can see if you can reproduce the error on your server using the following code and telling me the output (session worked is what you want):

    PHP Code:
    <?php
    session_start
    ();

    if( isset( 
    $_GET'destination' ] ))
    {
        echo isset( 
    $_SESSION'test' ] ) ? "Session worked" "Session failed";
        
    session_unset();
        exit();
    }

    $_SESSION'test' ] = true;

    header'Location: redirect.php?destination' );
    Also, to give us some information about what PHP version you're using (if none of the above works), run phpversion() and report the output.
    Last edited by Nile; 01-04-2014 at 09:18 PM.

  3. #13
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    Nile,

    Thank you for your continuing efforts.

    Code:
    <?php
    session_start(); //just for precaution
    
    if(isset( $_SESSION['visited'] ))
    {
        echo "Sessions appear to be working!";
        session_unset();
        exit;
    }
    
    $_SESSION['visited'] = true;
    echo "Session set attempted. Refresh.";
    ?>
    works, just as you describe.

    The output from
    Code:
    <?php
    echo 'session_cache_expire(): '.session_cache_expire().'<br>';
    echo 'session_cache_limiter(): '.session_cache_limiter();
    ?>
    is

    session_cache_expire(): 180
    session_cache_limiter(): nocache

    It will take me some time to try to distill the code to the ten or so lines that you seek.

  4. #14
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Interesting. So now we know that 1) the session is being set and retrieved properly, 2) your cache is configured properly, and 3) the error must have to do with something specifically in the code, and there isn't a problem with your server/php config.

    Before you try and reproduce the error yourself, I've already tried. While you were posting your new post, I went ahead and modified my previous post (#12, link here). Take a look at that one and run through the options I provide. If anything works, it'll save you from reproducing the error. Also - remember that reproducing isn't distilling. Distilling takes forever. Reproducing should take around 10 minutes. You aren't removing anything, you're starting over using a clean slate, and making the error occur again to make sure you weren't crazy the first time. In this process, you only are focused on what creates the error, and not all the in-betweens.
    Last edited by Nile; 01-04-2014 at 09:31 PM.

  5. #15
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by marain View Post
    Your suspicion that either session indices are not being set, or that sessions are not being carried over, is entirely correct. That tends to beg the question, of course, as to "why?"
    Have you tried using print_r( $_SESSION ); at the top of your quotations page, to see what values are being carried over?


    Quote Originally Posted by Nile View Post
    After searching Google for setting sessions then redirecting, I'm finding other users that have had the same problems as you (I've tried to reproduce but it all works okay). Below I'll list a few solutions I've seen.
    • Use session_write_close() before or after the header redirect …
    • I've seen people using exit(); and claim that putting it after the redirect fixes this issue …
    • I've also seen someone try and set the PHPSESSID cookie in the header …
    Try session_write_close before the redirect. I've **never** run into this problem (I haven't even seen mention of it more recently than 6 years ago), but if you have an odd configuration or a slow hard drive I suppose it might be a problem.

    And using exit after redirecting is good practice anyway.

    As for setting a new session cookie manually, I'd avoid trying that unless nothing else works (too much opportunity for things to get mixed up even more).

  6. #16
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by traq View Post
    I've **never** run into this problem (I haven't even seen mention of it more recently than 6 years ago), but if you have an odd configuration or a slow hard drive I suppose it might be a problem.
    I've never had this issue either, but searching Stackoverflow seems to bring up many (sadly recent) results. Here is a nice checklist to follow for the OP that I just found while searching.

    Quote Originally Posted by traq View Post
    As for setting a new session cookie manually, I'd avoid trying that unless nothing else works (too much opportunity for things to get mixed up even more).
    I agree. I would be worried about users who aren't using cookies at all (i.e., have them disabled). If sessions are only working when cookies are enabled because you have to set the session manually it could get rather confusing.

  7. #17
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Thumbs down

    Nile,

    None of the suggested additions solve the problem. I've not yet had a chance to create the "reproduce" file. I use PHP version 5.2.9.

    A.

  8. #18
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Did you try my own reproduction of the issue (pasted below):
    PHP Code:
    <?php
    session_start
    ();

    if( isset( 
    $_GET'destination' ] ))
    {
        echo isset( 
    $_SESSION'test' ] ) ? "Session worked" "Session failed";
        
    session_unset();
        exit();
    }

    $_SESSION'test' ] = true;

    header'Location: redirect.php?destination' );
    If it says session failed then we've potentially reproduced this issue.

  9. #19
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    Nile,

    I'll respond to your post #18 shortly.

    I was not familiar with stackoverflow. Just went there, saw the relevant dialogue. One of the items on the checklist is "8.Make sure your file extension is .php (it happens!)". My site sets defines the session index in a file with a .php extension, but it redirects to a .txt extension! My domain where sessions works uneventfully involves redirects to files with .php extensions. That strikes me as something to try. I think that setting that up, for me, won't be easy, on account of the present file navigation scheme.

    A.

  10. #20
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Nile View Post
    Did you try my own reproduction of the issue (pasted below):
    PHP Code:
    <?php
    session_start
    ();

    if( isset( 
    $_GET'destination' ] ))
    {
        echo isset( 
    $_SESSION'test' ] ) ? "Session worked" "Session failed";
        
    session_unset();
        exit();
    }

    $_SESSION'test' ] = true;

    header'Location: redirect.php?destination' );
    If it says session failed then we've potentially reproduced this issue.
    I attempted to try it, got 404-type error.

Similar Threads

  1. Refill "File" form field with stored image data
    By pelaej in forum MySQL and other databases
    Replies: 3
    Last Post: 10-22-2010, 07:28 PM
  2. sql stored procedure
    By aldo007 in forum MySQL and other databases
    Replies: 0
    Last Post: 08-30-2010, 01:41 PM
  3. Types of data to be stored in an array
    By heavensgate15 in forum PHP
    Replies: 1
    Last Post: 05-14-2010, 05:10 PM
  4. Increment a Value Stored in the DB
    By Moshambi in forum MySQL and other databases
    Replies: 3
    Last Post: 04-08-2009, 11:21 AM
  5. login script "user data not found"
    By jimo in forum PHP
    Replies: 10
    Last Post: 01-13-2007, 07:10 PM

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
  •