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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -