I got this code:
if( empty ($cache[$id]) ) {
$arr[$id] = @TIMENOW;
setcookie('id', cArr($arr, 'set'), -1, @PATH);
} else {
$cache[$id] = @TIMENOW;
setcookie('id', cArr($cache, 'set'), -1, @PATH);
}
And it is adding only one key, to the cookie
, if I'll go to the another thread , it'll reset the array, and won't add more keys. I mean, if the user goes to the thread with id
1 then if( empty ($cache[1]) )
is adding 1, instead it'll update existing value, AND if user will go now to the thread with ID 5, it will do the same, and if( empty ($cache[5]) )
is empty , then it'll add the key with ID 5 to the array so I'll have both keys now: 1 and 5.
Hope you got it. If you don't , feel free to ask for whatever you wan't, I'll reply for all of your quesitons.
It would be helpful to know what you're doing in cArr()
. But without it, this will add to your cookie for each new thread a user visits.
//get previous values
$id = $_GET['thread_id'];
$cache = array_key_exists('id', $_COOKIE) ? unserialize($_COOKIE['id']) : array();
//add to $cache
$cache[$id] = TIMENOW;
setcookie('id', serialize(cArr($cache, 'set')), -1, PATH);
WARNING: But keep in mind, that with just setting a cookie, your webserver can be exploited. So better not use searialize
and unserialize
to store simple static values inside your cookie.