Roee Posted July 16, 2006 Share Posted July 16, 2006 helloim useing phpbbforumsthe cookie which phpbb puts on my computer named: phpbb_datain this cookie there are 2 things:-autologin-useridafter 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: unserializethanks Quote Link to comment https://forums.phpfreaks.com/topic/14776-phpbb-cookie-with-unserialize/ Share on other sites More sharing options...
wildteen88 Posted July 16, 2006 Share Posted July 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14776-phpbb-cookie-with-unserialize/#findComment-58998 Share on other sites More sharing options...
Roee Posted July 16, 2006 Author Share Posted July 16, 2006 it doesnt workit is noneit writes nothing Quote Link to comment https://forums.phpfreaks.com/topic/14776-phpbb-cookie-with-unserialize/#findComment-59004 Share on other sites More sharing options...
wildteen88 Posted July 16, 2006 Share Posted July 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14776-phpbb-cookie-with-unserialize/#findComment-59010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.