note 13340 deleted from function.setcookie by sniper
| From: | sniper@php.net | Date: | Wed, 11 Dec 2002 07:11:39 +0000 |
| Subject: | note 13340 deleted from function.setcookie by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-40704@lists.php.net to get a copy of this message | ||
Hey guys...
First off... thank you for all your input... it all has been a great help to me in the past and
currently. Below is a script that I hacked up from a lot of the examples above. It is very simple:
it sets an multidimentional array, serializes it, sets it in a cookie, and displays the serialized
data. After 5 seconds it refreashes and it shows you the cookie info.
I created this example for people like me that needed to see how to store more then 20 items. I
plan on using this to store a lot of records into an array and place the serialized array into
either a cookie or a hidden form variable. I hope it helps you out... and I can not take credit for
a lot the code... I can only take credit for the idea involved... the credit goes to the folks above
:)
<? function print_array($array) {
if(gettype($array)=="array") {
echo "<ul>";
while (list($index, $subarray) = each($array) ) {
echo "<li>$index <code>=></code> ";
print_array($subarray);
echo "</li>";
}
echo "</ul>";
} else echo $array;
}
if(!$CCHK) {
$temp_array = array (
"temp1" => array ("a"=>"orange",
"b"=>"banana", "c"=>"apple"),
"temp2" => array (1, 2, 3, 4, 5, 6),
"temp3" => array ("first", 5 => "second",
"third"),
"temp4" => array ("a"=>"orange",
"b"=>"banana", "c"=>"apple"),
"temp5" => array (1, 2, 3, 4, 5, 6),
"temp6" => array ("first", 5 => "second",
"third")
);
$temp_serial = serialize($temp_array);
setcookie("temp",$temp_serial);
header("Refresh: 5;url=$PHP_SELF?CCHK=1");
echo $temp_serial;
} else {
echo "temp = ".$temp."< br>< br>\n";
$temp_array2 = unserialize (stripslashes($temp));
echo "Unserialized = ".$temp_array2."< br>< br>\nArray = ";
print_array($temp_array2);
echo "\n";
} ?>
* Note: Sorry about the spaces in the < br> tag... forum limitations.