I don't seem to understand how to serialize information and set that information into cookies.
I've looked up several threads including http://www.phpbuilder.com/forum/read.php3?num=2&id=121322&thread=121068
I can play with those examples, but I have not idea why this function is not working.
I'd love any help anyone could give me. I'm sure this is really basic, but I'm definately missing some big piece(s).
<?php
FUNCTION insert_question_into_cookie($array_w_q_data,$num_of_cookie) {
$temp = serialize($array_w_q_data);
setcookie ("cookie_number_${num_of_cookie}",$temp,time()+3600);
return;
};
FUNCTION display_cookie_content($cookie_name) {
GLOBAL $filling;
$filling = unserialize("question_${cookie_name}");
echo $filling[a].$filling.$filling[d].$filling[e].$filling[f].$filling[g];
display_data($filling[a],$filling,$filling[c],$filling[d],$filling[e],$filling[f],$filling[g]);
return;
};
FUNCTION display_data($a1,$a2,$a3,$a4,$a5,$a6,$a7) {
echo $a1."<br>";
echo $a2."<br>";
echo $a3."<br>";
echo $a4."<br>";
echo $a5."<br>";
echo $a6."<br>";
echo $a7."<br>";
return;
};
#$result= mysql_query("SELECT a,b,c,d,e,f FROM WHERE id=1",$link_id);
#$cart = mysql_fetch_array($result);
#the following is an example of what the query pulls.I"m not sure this matters though.
#$cart[a] = 0;
#$cart= "contains text1 it's fun";
#$cart[c] = "containstext2 to test";
#$cart[d] = "containstext3";
#$cart[e] = "containstext4";
#$cart[f] = "contains text5";
$cart[g]=$cart[f]." is only the beginning";
insert_question_into_cookie($cart,"1");
?>
<BODY>
serialized data = <?php echo $filling; ?> <br>
<?php display_cookie_content($cart) ?>
<a href="page_2.php">next page</a>
</BODY>
AND the second page is:
<pre>
<?php
echo $cart;
display_cookie_content($cart);
FUNCTION display_cookie_content($cookie_name) {
GLOBAL $filling;
$filling = unserialize("question_${cookie_name}");
echo $filling[a].$filling.$filling[d].$filling[e].$filling[f].$filling[g];
display_data($filling[a],$filling,$filling[c],$filling[d],$filling[e],$filling[f],$filling[g]);
return;
};
FUNCTION display_data($a1,$a2,$a3,$a4,$a5,$a6,$a7) {
echo $a1."<br>";
echo $a2."<br>";
echo $a3."<br>";
echo $a4."<br>";
echo $a5."<br>";
echo $a6."<br>";
echo $a7."<br>";
return;
};
?>
</pre>
It doesn't seem to work at all. I can't get the serialized data to display on page one. I can't find the cookie on page 2.
Driving me nuts.
thanks,
Bryan