Answer the question
In order to leave comments, you need to log in
Why are $_COOKIEs written but read as stale after page reload?
The site records and reads from cookies. The write goes fine, but the read after reloading the page does not behave as expected - it reads obsolete cookies.
Here is the read script:
if(isset($_COOKIE['JobsChess'])){
echo $_COOKIE['JobsChess'];
}else{echo "no_have_cookies";}
And a slightly larger entry
$have_cookies = isset($_COOKIE['JobsChess']);
$str = "";
if(!$have_cookies){
setcookie('JobsChess', "", time()+60*60*24*60, '/');
}
$nomber=$_GET['nomber'];
$nomberAr = explode(";",$nomber);
if($have_cookies){
$str = $_COOKIE['JobsChess'];
$str_ar = explode(";",$str);
foreach ($numberAr as &$value) {
$and = in_array($value, $str_ar);
if(!$and){
$str = $str.";".$value;
}
}
}else{
$str = $number;
}
setcookie('JobsChess', "", time()+60*60*24*60, '/');
setcookie('JobsChess', $str, time()+60*60*24*60, '/');
echo "Cookies: \t";
var_dump($_COOKIE['JobsChess']);
echo "Number: \t";
var_dump($number);
echo "Str:\t";
var_dump($str);
Everything works fine on the local server. Tell me, what could be the reason?
Answer the question
In order to leave comments, you need to log in
I don’t know why, but everything turns out to work (I checked the watermelon on others and in chrome from under a different account)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question