Click to See Complete Forum and Search --> : Urgent problem - a computer is not keeping the phpsessid


dave17
04-11-2007, 09:48 AM
Hi,

I'm having a very strange problem with with php sessions. I haven't ran into this problem until now and I can only reproduce it on one machine, unfortunately it's the machine that is being used to demo an application. The application requires sessions to run, but for some reason, this computer seems to be flushing or losing the phpsessid... which obviously makes the application not work at all. Here are some symptoms/details:

- Only happens on this one computer (about a dozen or so have been tried and not had the problem).
- PHP is 5.1.8, the browser being used is IE7 on winxp.
- Seems that the session is deleted when/after the page is loaded. When it is loading, it has the PHPSESSID alright. Then when I reload the page, it has lost it somehow.
- I did a test page that just starts a session, then var_dumps $_COOKIE and $_SESSION and the computer works as expected. When you refresh the page or go to/from it... it keeps the same session variable, so I dont think it is a problem with the computer being able to store cookies.

I really cant figure this out, I'll be going through my code line by line in a minute, but I cant imagine how it would lose the session like that. Any help would be very useful as this has to be demoed tonight lol.

dave17
04-11-2007, 10:16 AM
Well I just kept moving these lines of code around to find out what was causing the problem lol:

<?
session_start();
var_dump($_SESSION);
echo "<br><br>";
var_dump($_COOKIE);
exit();
?>

And it turns out that the problem occurs when I use the function session_set_cookie_params to extend the lifetime of the cookie.

$session_lifetime = 2*60*60;
session_set_cookie_params($session_lifetime);

Actually, I set the session cookie lifetime (the session started by a page that redirected it here) before I actually started the session on this page. Moving session_start() to before session_set_cookie_params() makes it work fine. This is still a bit strange to me though, what would cause it to work on most computers and not this one in particular? Besides Murphy's Law that is lol.