I have a script which takes arrays to shuffle them and then stores them into a cookie, so that user will have shuffled array only once.
Here's the script:
$shufflecookie = $_COOKIE['shuffle'];
if (isset($_COOKIE['shuffle'])) {
$items = unserialize(gzuncompress(base64_decode($shufflecookie)));
}
else {
shuffle($items);
$items_serialized = base64_encode(gzcompress(serialize($items)));
setcookie("shuffle", $items_serialized, 0, "/");
}
Is it safe to do that? or maybe there's better way of storing this data? Thanks
UPD. Thanks for helping. What I did is just replaced cookie with session. So new code is:
$shufflecookie = $_SESSION["shuffle"];
if (isset($_SESSION["shuffle"])) {
$items = unserialize(gzuncompress(base64_decode($shufflecookie)));
}
else {
shuffle($items);
$items_serialized = base64_encode(gzcompress(serialize($items)));
$_SESSION["shuffle"] = $items_serialized;
}