2

example:

$_SESSION['10'] = 'testing';
echo $_SESSION['10'];

The above will not print out anything...i found out(after a long time of frustration) that you cannot use a string numeral as a index for the $_SESSION variable. Anyone know why?

dave
  • 14,991
  • 26
  • 76
  • 110
  • your code is working at my pc. please check you have not forgot to **start a sesstion** `session_start();` – Dipesh Shihora May 16 '15 at 04:31
  • 2
    [Because](http://stackoverflow.com/questions/18797251/notice-unknown-skipping-numeric-key-1-in-unknown-on-line-0) the keys in `$_SESSION` must be names that could be treated as variables in their own right. – someOne May 16 '15 at 04:34
  • @someone you sir are a genius and i owe you lots of hours of frustration...lol ty. can you post as answer, ill check it off asap. – dave May 16 '15 at 04:35

1 Answers1

2

Quote from here:

The PHP session storage mechanism was originally built around "registering" variables, so the keys in $_SESSION must be names that could be treated as variables in their own right. This means that $_SESSION[10] is invalid, because $10 wouldn't be a valid variable name, and since $foo[10] and $foo['10'] refer to the same thing, $_SESSION['10'] is invalid as well.

Community
  • 1
  • 1
someOne
  • 1,975
  • 2
  • 14
  • 20