mewhocorrupts Posted September 26, 2006 Share Posted September 26, 2006 I'm having an issue with setcookie() and serialize()/unserialize().Here's the code that works with setcookie():[code]<?phpsetcookie("Test[1]", "test1");setcookie("Test[2]", "test2");setcookie("Test[3]", "test3");if (isset($_COOKIE['Test'])){ foreach($_COOKIE['Test'] as $k => $v) { echo "$k => $v <br>"; }}?>[/code]That's fine, I get that. The issue I'm having is that I want to try and serialize an array of user information, and then store it in a cookie. The problem is that absolutely nothing happens. Here's the code so far:[code]<?php$carr = array("un" => "test","up" => "pass","li" => 1,"something" => "else");$carr_ser = serialize($carr);setcookie("SerCookie", $carr_ser);echo "$carr_ser <br>";foreach($carr as $k => $v){ echo "$k => $v <br>";}$stored = $_COOKIE['SerCookie'];$stored_arr = unserialize($stored);foreach($stored_arr as $k => $v){ echo "$k => $v <br>"}?>[/code]I'm not sure what I've done wrong. If the first round of code works, the second should be less likely to err. I can't see errors because our server has error reporting turned off for some of the code that we have, particularly eval(). I can test some more when I get home tonight, but if I can hash it out now, I can make it to the bar in time to play poker. ;D Quote Link to comment https://forums.phpfreaks.com/topic/22137-cookies-and-serialize-not-good-in-the-morning/ Share on other sites More sharing options...
Daniel0 Posted September 26, 2006 Share Posted September 26, 2006 Which results do you get? Quote Link to comment https://forums.phpfreaks.com/topic/22137-cookies-and-serialize-not-good-in-the-morning/#findComment-99126 Share on other sites More sharing options...
mewhocorrupts Posted September 26, 2006 Author Share Posted September 26, 2006 That's the thing, I don't get any output. None at all. At the very least, $carr_ser should output, but it doesn't. Quote Link to comment https://forums.phpfreaks.com/topic/22137-cookies-and-serialize-not-good-in-the-morning/#findComment-99139 Share on other sites More sharing options...
mewhocorrupts Posted September 26, 2006 Author Share Posted September 26, 2006 So I finally got some output. When I print_r($_COOKIE);, it shows me all of the cookies on my system, which includes my "Test" cookie from above. The thing is, it wont' let me access it with $_COOKIE['Test']. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/22137-cookies-and-serialize-not-good-in-the-morning/#findComment-99202 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.