You may have trouble if you use '|' in the key:
$_SESSION["foo|bar"] = "fuzzy";
This does not work for me. I think it's because the serialisation of session object is using this char so the server reset your session when it cannot read it.
To make it work I replaced '|' by '_'.
$_SESSION -- $HTTP_SESSION_VARS [已弃用] — Session 变量
当前脚本可用 SESSION 变量的数组。更多关于如何使用的信息，参见 Session 函数 文档。
$HTTP_SESSION_VARS 包含相同的信息，但它不是一个超全局变量。 (注意 $HTTP_SESSION_VARS 和 $_SESSION 是不同的变量，PHP 处理它们的方式不同)
|4.1.0||引入 $_SESSION，弃用 $HTTP_SESSION_VARS。|
“Superglobal”也称为自动化的全局变量。这就表示其在脚本的所有作用域中都是可用的。不需要在函数或方法中用 global $variable; 来访问它。
- session_start() - Start new or resume existing session
Please note that if you have register_globals to On, global variables associated to $_SESSION variables are references, so this may lead to some weird situations.
$_SESSION['test'] = 42;
$test = 43;
Load the page, OK it displays 42, reload the page... it displays 43.
The solution is to do this after each time you do a session_start() :
foreach ($_SESSION as $key=>$value)
Unlike a real PHP array, $_SESSION keys at the root level must be valid variable names.
$_SESSION = 'cake'; // fails
$_SESSION['v1'] = 'cake'; // works
I imagine this is an internal limitation having to do with the legacy function session_register(), where the registered global var must similarly have a valid name.
If you deploy php code and cannot control whether register_globals is off, place this snippet in your code to prevent session injections:
if (isset($_REQUEST['_SESSION'])) die("Get lost Muppet!");
When accidently assigning a unset variable to $_SESSION, like
$_SESSION['foo'] = $bar
while $bar was not defined, I got the following error message:
"Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. "
The errormessage was quite unrelated and got me off-track. The real error was, $bar was not defined.
I was having troubles with session variables working in some environments and being seriously flaky in others. I was using $_SESSION as an array. It works properly when I used $_SESSION as pointers to arrays. As an example the following code works in some environments and not others.
//Trouble if I treate $form_convert and $_SESSION['form_convert'] as unrelated items
The following works well.
$form_convert = $_SESSION['form_convert'];
$form_convert = array();