Jump to content

Archived

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

mewhocorrupts

Cookies and Serialize()... not good in the morning.

Recommended Posts

I'm having an issue with setcookie() and serialize()/unserialize().

Here's the code that works with setcookie():
[code]
<?php

setcookie("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

Share this post


Link to post
Share on other sites
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?

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.