|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-07-20 13:23 UTC] simon dot bettison at blueyonder dot co dot uk
Description:
------------
A script registers a variable in $_SESSION using and index value which contains a pipe ("|"),
ie
$index = "some|index";
$_SESSION[$index]="some variable";
I expected this variable (and any other variables registered in $_SESSION) to be stored, and made available to other script(s) executed in the same session for the lifetime of the session cookie.
However, subseqent access to $_SESSION indicates that the $_SESSION variable contains no data at all.
This only seems to occur following the use of the pipe ("|") character in the element's index.
Reproduce code:
---------------
<?php
session_start();
print_r($_SESSION);
$_SESSION["some|variable"]="some value";
print_r($_SESSION);
?>
Expected result:
----------------
First execution:
Array ( ) Array ( [some|variable] => some value )
Second & Subsequent execution
Array ( [some|variable] => some value ) Array ( [some|variable] => some value )
Actual result:
--------------
First execution:
Array ( ) Array ( [some|variable] => some value )
Second & Subsequent execution
Array ( ) Array ( [some|variable] => some value )
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
I assume this is because the serialized form of sessions (as for the PHP serialization handler) contains the pipe character "|" as a separator between variable names. The pipe example: <?php $_SESSION['a|b'] = 'c'; echo session_encode(); # '' - empty string ?> I assume this, because other illegal variable names, like a variable starting with a number, _are_ possible, for example: <?php $_SESSION['0a'] = '1a'; echo session_encode(); # '0a|s:2:"1a";' ?> If you change the session serialize-handler to "php_binary" (was: "php" in the exmaples above), this might already work (returns values containing the data in both cases). Tested against PHP 5.3.8.