0
votes

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]

2
oops it was pid everywhere... kind of pasted a prev version.CodeMonkey
What if you echo $pid? Do you get the expected results?KristofMorva
it is giving correct value...CodeMonkey
Maybe it's a stupid idea, but what if you are storing $_SESSION["a$i"] and use pid=a$i? Maybe something is messing up with numeric indexes.KristofMorva
You should take a look at the following post: stackoverflow.com/questions/18797251/…. To clarify, try adding a character prefix instead of just using numbers.user1601671

2 Answers

2
votes

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.

1
votes

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.