开发者

PHP sessions passing values through offsets

I am working on the following code in file1

$_SESSION['manu']="hello";
$_SESSION[0]=$msg;
$_SESSION[1]=$msg1;
for($arr=0;$arr<sizeof($msg2);$arr++)
    $_SESSION[$arr+2]=$msg2[$arr];
$_SESSION[++$arr]=$msg3;
$_SESSION[++$arr]=$file_nam开发者_运维问答e;

In file 2

echo sizeof($_SESSION);
for($arr=0;$arr<sizeof($_SESSION);$arr++)
    echo $_SESSION[$arr];
echo $_SESSION['manu'];

However the sizeof session comes out to be 1 in file2 and all my session values stored in offset forms are lost?


The names of the elements in the $_SESSION array are subject to the same limitations as normal PHP variables: they cannot start with a number and must start with a letter or underscore.

So, using numbers as a session element is not allowed. That is why you lose them in the transition.
(If you had error reporting turned on you would have gotten an error notice.)

Rather than do:

$_SESSION[0] = $msg;
$_SESSION[1] = $msg1;

Try:

$_SESSION['msg'][0] = $msg;
$_SESSION['msg'][1] = $msg1;


Have you put session_start() somewhere on top of your file? Add it in case there isn't one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜