Jump to content

Archived

This topic is now archived and is closed to further replies.

Roee

PHPBB cookie with unserialize

Recommended Posts

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

Share this post


Link to post
Share on other sites
Whn you use unserialize, it turns the serialized data into an array. So basically do this:
[code=php:0]// unserialize the phpbb_date cookie data
$cookie = unserialize($_COOKIE[phpbb_date]);

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

echo $userid; // 2[/code]

Share this post


Link to post
Share on other sites
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:
[code]<?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';
}

?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.