Session variable not persisting
| From: | Éric Oliver Paquette | Date: | Mon, 18 Mar 2013 18:46:39 +0000 |
| Subject: | Session variable not persisting | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-320636@lists.php.net to get a copy of this message | ||
Hi all,
I'll be swift in my explanation as I can't find in any way the source of the problem; it
seems to be installation-related.
At execution, sometimes (randomly it seems at first), variable session aren't properly stored.
=====================
First things first, about installation :
uname -a -m -p yields :
Linux cl-t180-253cl.privatedns.com 2.6.18-308.1.1.el5 #1 SMP Wed Mar 7 04:16:51 EST 2012 x86_64
x86_64 x86_64 GNU/Linux
php -v yields :
PHP 5.3.3 (cli) (built: Jun 27 2012 12:25:48)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
=====================
To make sure it is not caused by any other part of my scripts, I just created two scripts that have
replicated the problem :
SCRIPT #1 [ping.php] ################
<?php
session_start();
if(count($_SESSION['in'])==0){
$_SESSION['in'][0]='0-initiate';
} else {
$_SESSION['in'][] = count($_SESSION['in']).$_GET['push'];
}
if(count($_SESSION['in'])<1000){
$rand = rand(0, 1000000);
?>
<meta http-equiv="refresh" content="0;URL='pong.php?push=<?php
echo $rand; ?>'">
<?php
} else {
var_dump($_SESSION);
}
?>
SCRIPT #2 [pong.php] ################
<?php
session_start();
if(count($_SESSION['in'])==0){
$_SESSION['in'][0]='0-initiate';
} else {
$_SESSION['in'][] = count($_SESSION['in']).$_GET['push'];
}
if(count($_SESSION['in'])<1000){
$rand = rand(0, 1000000);
?>
<meta http-equiv="refresh" content="0;URL='ping.php?push=<?php
echo $rand; ?>'">
<?php
} else {
var_dump($_SESSION);
}
?>
##################################
In fact, when I run this on my server I randomly have empty entries in the $_SESSION array. Any
thoughts on this? Is this a known bug (haven't found it…)
Thanks!