note 21259 deleted from function.setcookie by john
| From: | john@php.net | Date: | Sat, 30 Nov 2002 16:35:32 +0000 |
| Subject: | note 21259 deleted from function.setcookie by john | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-40172@lists.php.net to get a copy of this message | ||
I have found that the following works pretty well when saving an entire array as a cookie:
// PAGE 1
// set the array of data
$array_data = array("look", "at", "me");
// serialize and then encode the data
$encoded_data = base64_encode(serialize($array_data);
// set the cookie
setcookie("some_cookie", "$encoded_data", "time()+3600",
"/", "", 0);
// PAGE 2
// unserialize and then decode the data
$decoded_data = unserialize(base64_decode($_COOKIE["some_cookie"]));
// dump vars
echo var_dump($decoded_data);