Jump to content

Checking For A Cookie...


mhoctober

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
}

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.