mhoctober Posted March 31, 2006 Share Posted March 31, 2006 Guys...I am attempting to test for the existence of a cookie and take appropriat actions...however, this code ALWAYS displays "Cookie Set"when I load it into my browser.I an attempt to have it execute the Else section I have...- changed the name of the cookie on the If line- deleted cookies via IEBut alas - its always displaying "Cookie Set"is there something I am missing here? <?phpif (!isset($_COOKIE["ckBeenHere"])){echo "Cookie Set";}Else{echo "Cookie Not Set, Setting Cookie and Updating Counter";setcookie ("ckBeenHere", time()+43200); // will expire in 12 hours} Link to comment https://forums.phpfreaks.com/topic/6299-checking-for-a-cookie/ Share on other sites More sharing options...
azuka Posted March 31, 2006 Share Posted March 31, 2006 Youre using the wrong code. Change it to. [code]if (isset($_COOKIE["ckBeenHere"])){echo "Cookie Set";}else{echo "Cookie Not Set, Setting Cookie and Updating Counter";setcookie ("ckBeenHere", time()+43200); // will expire in 12 hours}[/code]You were checking if it had been set and echoing if it wasn't instead of the opposite Link to comment https://forums.phpfreaks.com/topic/6299-checking-for-a-cookie/#findComment-22761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.