简体   繁体   中英

php session variable is null

i am creating session variables to store data in an array of object. this array is assigned to sessions. I am later sending a get call to different page with an id and want to access the corresponding data from the sessions. however i am getting the data as null. here is my code

page 1:

session_start();
for ($i=0;$i<100;$i++){
    $object[$i]->name = $ret_obj[$i]['name'];
    $object[$i]->birthday_date = $ret_obj[$i]['birthday_date'];
    $_SESSION[$i] = $object[$i];
}

var_dump of session prints the session variable correctly.

Now in the for loop i am making a call to page 2:

page2.php?pid=$i

page 2:

session_start();
$pid = $_GET['pid'];
print_r($_SESSION[$pid]);
print_r($_SESSION);

I am getting value in $_SESSION but not in $_SESSION[$pid]

You should take a look at the following post: Notice: Unknown: Skipping numeric key 1 in Unknown on line 0 . To clarify, try adding a character prefix instead of just using numbers.

If your code supplied here is all of it, then you are saying:

$p13nid = $_GET['pid'];

Rather than:

$pid = $_GET['pid'];

Which would make it work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM