0

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]

8
  • oops it was pid everywhere... kind of pasted a prev version. Commented Feb 22, 2014 at 23:49
  • 1
    What if you echo $pid? Do you get the expected results? Commented Feb 22, 2014 at 23:52
  • it is giving correct value... Commented Feb 22, 2014 at 23:57
  • 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. Commented Feb 23, 2014 at 0:04
  • 1
    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. Commented Feb 23, 2014 at 2:50

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Also edit php.ini into error_reporting = E_ALL | E_STRICT
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.