Unable to set cookie if it does not already exist in PHP -
i trying set cookie site if not exist. not working.
if(isset($_cookie['about'])){ $_cookie['about'] += 1; } if(!isset($_cookie['about'])){ setcookie("about", 1, time()+3600); }
i have tried
if(empty($_cookie['about'])){ setcookie("about", 1, time()+3600); }
you can read stuff $_cookie
superglobal, try setting normally:
setcookie("about",$_cookie['about']+1,time()+3600);
so together:
if(isset($_cookie['about'])){ $_cookie['about'] += 1; }else{ setcookie("about", 1, time()+3600); }
note else, you've checked before if cookie isset, there no need check again either or isn't.
Comments
Post a Comment