FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a 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

regular expression
Formulate Regular Expression
Help with regular expression
PHP - Find and Delete
[JS] Regular expressions global match get first group

Complicated regular expression (for preg_replace)
Automating your Forum Signature with Perl
Echoing Titles
Perl server referencing
PHP Regex

mod_rewrite code
HTML: Automatically add ALT tags
[JavaScript]: Checking for undefined values
My Favorite Portable Applications
Help with User Form Validation
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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