Jump to content

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


mewhocorrupts

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