Quite simple code:
<?
session_start();
$_SESSION['t'.time()] = "ok";
echo "<pre>".print_r($_SESSION, 1)."</pre>";
?>
shows, as expected, something like
Array
(
[t1330966834] => ok
[t1330966835] => ok
[t1330966836] => ok
)
after 3page reloads.
Let’s change a few symbols:
$_SESSION[time()] = "ok";
(now without ‘t’) and I expect after few reloads something like
Array
(
[t1330966834] => ok
[t1330966835] => ok
[t1330966836] => ok
[1330967020] => ok
[1330967021] => ok
[1330967022] => ok
[1330967023] => ok
)
But actually the result is absolutely different:
Array
(
[t1330966834] => ok
[t1330966835] => ok
[t1330966836] => ok
[1330967020] => ok
)
We have 3 previous array cells ad one and only one ‘time’ cell – no matter how many times you reload the page. The time is correct, it different each second but only one cell without ‘t’!
Also I tried
$t =time();
$_SESSION[$t] = "ok";
and even
$t =intval(time());
$_SESSION[$t] = "ok";
But it’s remains only one cell with time.
Tested at php 5.2.13 and 5.3.10 at 2 different servers.
What am I doing wrong?
http://php.net/manual/en/session.examples.basic.php