I've done some testing with $_SESSION and $_COOKIE because I they weren't working as I expected. I'd like to know why these lines of code behave differently.
$_SESSION[1] = 'foo'; // Does not work because of the integer
$_COOKIE[1] = 'bar'; // Works
$_SESSION['foo bar'] = 'foo'; // Works with the space
$_COOKIE['foo bar'] = 'bar'; // Does not work
I would have thought $_SESSION and $_COOKIE would be identical, other than being server side vs. client side. Are there any other differences between the two?
The answers on this question address some of the issues involved, but the short answer is that there are different restrictions depending on whether it's a session or a cookie. Sessions are restricted space-wise by different php.ini settings, cookies don't allow spaces in keys, etc.