string(284) "a:4:{s:10:"session_id";s:32:"01a046827a00cf838a1b3ce585cc82fb";s:10:"ip_address";s:13:"124.43.56.156";s:10:"user_agent";s:120:"Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";s:13:"last_activity";i:1371099813;}"
This is a decrypted cookie from CodeIgniter. I need to access data from this. Preferably convert to an array or something which is easily accessible like data -> session_id
. Which would be the possible way to extract data from this?
Just unserialize it.
var_dump( unserialize('a:4:{s:10:"session_id";s:32:"01a046827a00cf838a1b3ce585cc82fb";s:10:"ip_address";s:13:"124.43.56.156";s:10:"user_agent";s:120:"Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";s:13:"last_activity";i:1371099813;}'));
That's a serialized string, just call unserialize
$array = unserialize($string);
and you have it back as array:
Array
(
[session_id] => 01a046827a00cf838a1b3ce585cc82fb
[ip_address] => 124.43.56.156
[user_agent] => Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
[last_activity] => 1371099813
)
I think its a serialized array. Use unserialize and get it to variable.
$arr = unserialize($str);
Use unserialize to convert the serialize string into array
$arr = unserialize($string);
print_r($arr) //will display you the array values