Jump to content


Photo

PHPBB cookie with unserialize


  • Please log in to reply
3 replies to this topic

#1 Roee

Roee
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 16 July 2006 - 04:32 PM

hello

im useing phpbbforums
the cookie which phpbb puts on my computer named: phpbb_data
in this cookie there are 2 things:
-autologin
-userid

after i did print_r($_COOKIE[phpbb_date]);
i got this:
a:2:{s:11:\"autologinid\";s:33:\"123392824444ba735af058d9.40304503\";s:6:\"userid\";s:1:\"2\";}

i want to know how to get the userid (a number) of this cookie..
i understood that the way to do it with: unserialize

thanks

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 July 2006 - 04:39 PM

Whn you use unserialize, it turns the serialized data into an array. So basically do this:
// unserialize the phpbb_date cookie data
$cookie = unserialize($_COOKIE[phpbb_date]);

// now to get the user id:
$userid = $cookie['userid'];

echo $userid; // 2


#3 Roee

Roee
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 16 July 2006 - 04:53 PM

it doesnt work
it is none
it writes nothing

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 July 2006 - 05:14 PM

Is the cookie set? And are you running the code of the server that the cookie was set at?

Also are you running the code at the same time the cookie is being set? If you are running this code at the same time the cookie is being set then the cookie wont be available untill the web browser is refreshed.

What does this produce:
<?php

$cookie_data = array("autologinid" => "123392824444ba735af058d9.40304503",
                     "userid" => "4");

setcookie('phpbb_date2', serialize($cookie_data), time()+3600);

if(isset($_COOKIE['phpbb_date2']))
{
    echo '<pre>' . print_r($_COOKIE['phpbb_date2'], true) . '</pre>';

    $cookie = unserialize($_COOKIE['phpbb_date2']);

    $userid = $cookie['userid'];

    echo $userid;
}
else
{
    echo 'Cookie has been set. Please refresh the browser window';
}

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users