FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Regular Expression - get content of a cookie





roeenoy
Hello,
The cookie which phpBB puts on my computer looks like that: (after i did: print_r($_COOKIE) ):

Code:
a:2:{s:11:"autologinid\";s:0:\"\";s:6:\"userid\";s:1:\"2\";} 


I want to get the number '2' which is after \"userid\"
( 2 is my userid )


thanks =]
hexkid
roeenoy wrote:
Hello,
The cookie which phpBB puts on my computer looks like that: (after i did: print_r($_COOKIE) ):

Code:
a:2:{s:11:"autologinid\";s:0:\"\";s:6:\"userid\";s:1:\"2\";} 


I want to get the number '2' which is after \"userid\"
( 2 is my userid )


thanks =]


Code:
echo $_COOKIE['autologinid']; // will print "" (without the quotes)
echo $_COOKIE['userid']; // will print "2" (without the quotes)
roeenoy
it doesn work...
i try to write:
Code:
echo $_COOKIE['userid'];


but it doesn work
Antoine_935
Code:
a:2:{s:11:"autologinid\";s:0:\"\";s:6:\"userid\";s:1:\"2\";} 


I'm sure it is a serialized value. You don't need no regexp for this, simply make:
Code:
$dataArray = unserialize($theString);

where theString is a:2:{s:11:"autologinid\";s:0:\"\";s:6:\"userid\";s:1:\"2\";} and dataArray the data this string contains
roeenoy
i wrote it but it doesnt work:
Quote:
$dataArray = unserialize("a:2:{s:11:"autologinid\";s:0:\"\";s:6:\"userid\";s:1:\"2\";}");
echo $dataArray;


it writes: parse error, unexpected T_STRING
Related topics
Echoing Titles
Perl server referencing
PHP - Find and Delete
[JS] Regular expressions global match get first group
regular expression
Complicated regular expression (for preg_replace)
Formulate Regular Expression
Automating your Forum Signature with Perl
Help with regular expression
Two validations process
.htaccess code help needed
Python Expression Evaluator Version 2
301 Redirect
Robots.txt and Meta Robots
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.