0

Possible Duplicate:
Firefox session cookies

I have this code

session_start();

$_SESSION['login'] = "bla";

var_dump($_SESSION);

If I execute this page in firefox, then delete this line $_SESSION['login'] = "bla"; from script, then close and reopen browser, firefox shows me: ["login"]=> string(3) "bla"

That is, firefox saves session datas after close browser. Why this happens ?

P.S. This happens only in firefox, other browsers all works as expected, that is result is empty array.

Community
  • 1
  • 1
Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236

2 Answers2

0

Are you sure you're testing the correct version of the script? You might want to add something else to the test script to be sure, for example, echo the current time of day.

One situation that might be in play here is the fact that all instances of a browser share the same cookie jar. In order to force the browser to remove the session cookies, you must close all windows and tabs. This is never a problem in "real life" but it often drives developers nuts when you can't seem to get logged out!

Ray Paseur
  • 2,106
  • 2
  • 13
  • 18
0

Firefox cannot save $_SESSION. $_SESSION is entirely a server side variable. It does not come to Firefox except that it will set a session cookie which is used only by php to find out the right user session on the server.

The reason you have been getting the ["login"]=> string(3) "bla" is because you had set it in the first run. Do this:

First run the script

session_start();

$_SESSION['login'] = "bla";

var_dump($_SESSION);

Then delete the $_SESSION['login'] = "bla"; line from the script and run it. It should still show that login key is set in session variable. Then run a separate script:

session_start();

$_SESSION['login'] = null;
// OR 
// unset($_SESSION['login']);

var_dump($_SESSION);

Then try to see the value of the Session variable and the value of 'login' key would be gone.

What I mean to say is: if you set something in the session, it will persist and you do not have to set it everytime the script runs. TO remove the value from session variable, you have to explicitly remove it.