views:

26

answers:

1

I have a session variable that contains the following string.

a:2:{s:7:"LoginId";s:32:"361aaeebef992bd8b57cb3e8d";s:8:"Username";s:6:"aaaaaa";}

echo $_SESSION["SecurityAccess_CustomerAccess"];

I am trying to extract the username "aaaaaa". What combination of unserialize, preg_split or other will get me there fastest?

attempts so far...

$session_data = unserialize($_SESSION["SecurityAccess_CustomerAccess"]);
$session_user_array = preg_split('%;%', $_SESSION["SecurityAccess_CustomerAccess"]);
echo $session_user_array[3];
+1  A: 

unserialize is by far the most reliable, as PHP's internal implementation of sessions may change.

Jacob Relkin
thanks. I have now extracted this part. s:6:"aaaaaa" Now reading the Regex manual to determine how to isolate the aaaaaa
big ralph