There are two blocks of PHP code
Block 1
<?php
setcookie("test_cookie","0",time()-3600);
if(empty($_COOKIE["test_cookie"])){
echo "First time browsing";
setcookie("test_cookie","1",time()+3600);
}else{
$count = $_COOKIE['test_cookie'];
$count++;
setcookie("test_cookie",$count,time()+3600);
echo "Cookie set as " . $_COOKIE["test_cookie"] ;
}
Block 2
<?php
if(empty($_COOKIE["test_cookie"])){
echo "First time browsing";
setcookie("test_cookie","1",time()+3600);
}else{
$count = $_COOKIE['test_cookie'];
$count++;
setcookie("test_cookie",$count,time()+3600);
echo "Cookie set as " . $_COOKIE["test_cookie"] ;
}
setcookie("test_cookie","0",time()-3600);
In Block 1 cookie named test is unset which should echo "first time browsing" but what i get is cookie count
In block 2 cookie named test is unset at last which echo "first time browsing" which is fine and i understand logic no matter what i set i unset at last which results in "first time browsing"
But what is wrong with with Block 1 i should have got same result as BLock 2 .. why am i getting Cookie count here ? Please do explain this in simplest way possible .