Cookies and simple data manipulation
Posted: Wed Dec 30, 2009 7:27 pm
This should be simple, but I can't get it to work now.
$score = $_COOKIE["score"];
if(isset($_COOKIE["hsPrev"])){
$hsPrevious = $_COOKIE["hsPrev"];
$hsPreviousSort = explode(",", $hsPrevious, 6);
}else{
$hsRecord = $score;
setcookie("hsPrev", $hsRecord);
}
the above doesn't work and the code I had which was mostly working is gone now.
$score will equal say 5.
This score is to be stored in the cookie hsPrev.
Say the next score = 2. Should be stored/appended to the end of the cookie also i.e. "5,2"
I only want their to be 5 scores in the cookie (i.e. say "4,2,12,3,9"), the 5 latest, so the older scores should be removed and this is predominantly where I am having trouble. Can someone help me with this?
$score = $_COOKIE["score"];
if(isset($_COOKIE["hsPrev"])){
$hsPrevious = $_COOKIE["hsPrev"];
$hsPreviousSort = explode(",", $hsPrevious, 6);
}else{
$hsRecord = $score;
setcookie("hsPrev", $hsRecord);
}
the above doesn't work and the code I had which was mostly working is gone now.
$score will equal say 5.
This score is to be stored in the cookie hsPrev.
Say the next score = 2. Should be stored/appended to the end of the cookie also i.e. "5,2"
I only want their to be 5 scores in the cookie (i.e. say "4,2,12,3,9"), the 5 latest, so the older scores should be removed and this is predominantly where I am having trouble. Can someone help me with this?