Jump to content


Photo

Checking For A Cookie...


  • Please log in to reply
1 reply to this topic

#1 mhoctober

mhoctober
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 31 March 2006 - 09:41 PM


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 IE

But alas - its always displaying "Cookie Set"

is there something I am missing here?

<?php
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
}



#2 azuka

azuka
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 31 March 2006 - 10:11 PM

Youre using the wrong code. Change it to.

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
}


You were checking if it had been set and echoing if it wasn't instead of the opposite
Given enough eyeballs all bugs are shallow. My Website




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users