Jump to content

PHPBB cookie with unserialize


Roee

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
Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.