note 69926 deleted from ref.session by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 16:02:59 +0000 |
| Subject: | note 69926 deleted from ref.session by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134308@lists.php.net to get a copy of this message | ||
Note Submitter: jon at jonroig dot -----com
----
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');
?>