Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 mewhocorrupts

mewhocorrupts
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationParker, CO

Posted 26 September 2006 - 06:07 PM

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

Here's the code that works with setcookie():
<?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>";
  }
}

?>

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:
<?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>"
}

?>

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
-mewhocorrupts

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 26 September 2006 - 06:21 PM

Which results do you get?

#3 mewhocorrupts

mewhocorrupts
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationParker, CO

Posted 26 September 2006 - 06:41 PM

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.
-mewhocorrupts

#4 mewhocorrupts

mewhocorrupts
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationParker, CO

Posted 26 September 2006 - 08:39 PM

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?
-mewhocorrupts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users