Jump to content

Archived

This topic is now archived and is closed to further replies.

mhoctober

Checking For A Cookie...

Recommended Posts


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
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.