note 21259 added to function.setcookie
| From: | dpknc84 at msn dot com | Date: | Sun, 05 May 2002 18:33:08 +0000 |
| Subject: | note 21259 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30223@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);
--
http://www.php.net/manual/en/function.setcookie.php
http://master.php.net/manage/user-notes.php?action=edit+21259
http://master.php.net/manage/user-notes.php?action=delete+21259
http://master.php.net/manage/user-notes.php?action=reject+21259