note 69926 modified in ref.session by bobby
| From: | bobby@php.net | Date: | Wed, 27 Sep 2006 14:28:45 +0000 |
| Subject: | note 69926 modified in ref.session by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117716@lists.php.net to get a copy of this message | ||
This code is to solve a problem that's probably becoming more common as we move into the AJAX
world -- how the &*^*&^ to access session data if you're transferring data back
'n' forth from a server and you don't have cookies to help you out.
The function accepts the session ID then grabs the session data straight from the directory, parses
it, and returns it as an array.
<?
function grabSessionData($sessionInput)
{
$sessionThing = "/tmp/sess_".$sessionInput;
$textContentsArray = file($sessionThing);
$serializedData = '';
foreach ($textContentsArray as $line => $textLine)
{
$serializedData = $serializedData.$textLine;
}
$sessionArray = explode(";",$serializedData);
$sessionDataArray = array();
foreach ($sessionArray as $line => $dataLine)
{
$dataArray2 = explode('|',$dataLine);
$dataArray3 = explode(':',$dataLine);
$sessionDataArray[$dataArray2[0]] =
str_replace('"','',$dataArray3[count($dataArray3)-1]);
}
return $sessionDataArray;
}
// example
$sessionInfoArray = grabSessionData('f58c92b76c1dd553c56dd428ea7a1bfc');
?>
--was--
<?
function grabSessionData($sessionInput)
{
$sessionThing = "/tmp/sess_".$sessionInput;
$textContentsArray = file($sessionThing);
$serializedData = '';
foreach ($textContentsArray as $line => $textLine)
{
$serializedData = $serializedData.$textLine;
}
$sessionArray = explode(";",$serializedData);
$sessionDataArray = array();
foreach ($sessionArray as $line => $dataLine)
{
$dataArray2 = explode('|',$dataLine);
$dataArray3 = explode(':',$dataLine);
$sessionDataArray[$dataArray2[0]] =
str_replace('"','',$dataArray3[count($dataArray3)-1]);
}
return $sessionDataArray;
}
// example
$sessionInfoArray = grabSessionData('f58c92b76c1dd553c56dd428ea7a1bfc');
?>
http://php.net/manual/en/ref.session.php