I'm trying to store an array in a cookie so that a site visitor could set a different number of items per page for different categories:
if (isset($_POST['pglimit'])) {
if (isset($_COOKIE['pglimit'])) {
$pglimit[$category] = $_POST['pglimit'];
} else {
$pglimit = array($category=> $_POST['pglimit']);
}
setcookie("pglimit", serialize($pglimit));
header("Location: " . $base_url);
exit;
} elseif ((isset($_COOKIE['pglimit'])) && (!isset($_POST['pglimit']))) {
$pglimit2 = unserialize(stripslashes($_COOKIE['pglimit']));
/* See the cookie guts */
foreach($pglimit2 as $key => $value) {
echo "$key: $value<br>";
}
echo "page limit is " . $pglimit2[$category];
$pglimit = $pglimit2[$category];
} else {
$pglimit = $default_pglimit;
}
It works... partially. The problem is, i can't for the life of me store more than one key and one value in the array as the old ones are being overwritten. I'm sure the error is obvious but being a beginner, i'm unable to locate it. Any help is greatly appreciated.