tags:

views:

42

answers:

2

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_name;

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? Why?

+1  A: 

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

Sarfraz
yes.. i did the problem lies somewhere else as it perfectly shows an enumerated session $_SESSION['manu'];
manugupt1
+1. You can not even imagine how many times have I done this :p
Ondrej Slinták
+1  A: 

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;
Atli
i did notice the errors
manugupt1