Reputation: 11
Okey im pretty new to php/javascript but what i would need to do is read cookie and then parse some part of it. How can i do it easily? php or javascript or okey.
Cookie has something like this info: ssf.2313.1333 and I would need to get middle numrbers (2313).
Upvotes: 1
Views: 2430
Reputation: 1
If you have the ability to create the cookie, I would suggest serializing an array with data. This way, you have far more control when reading the cookie.
Example:
$information = array(
'one' => 'data1',
'two' => 'data2'
);
$ck = setcookie('cookiename', serialize($information), time()+3600);
When fetching the cookie, use the PHP function unserialize, like so:
$ck = unserialize($_COOKIE['cookiename']);
echo $ck['one']; // returns 'data1'
Upvotes: 0
Reputation: 8366
You can do it using PHP easily.
$pieces = explode('.',$_COOKIE['yourcookiename']);
echo $pieces[1];
Upvotes: 3