showing cookie not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

showing cookie not working

Post by tomsace »

I have managed to get the code to save the cookie to my computer using the following code:

Code: Select all

<?php setcookie("excludeAnalytics", excludeAnalytics, time()+31536000, "/", ".zippygame.com", 1); ?>
Now I cant use the cookie, when I try to echo it or use it, it still doesn't work?? I have tried using:

Code: Select all

<?php
if(isset($_COOKIE['excludeAnalytics']))
  { echo "Showing"; }
else
  { echo "Not Showing"; } ?>
This is so that I can show some text if the cookie exists, or show something else if the cookie doesn't exist.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: showing cookie not working

Post by requinix »

You passed 1 as the 'secure' argument. That means the cookie will only be set over a secure (HTTPS) connection. Was that intentional?

Have you verified that the cookie actually exists on your computer?
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: showing cookie not working

Post by tomsace »

Oh right, yes I was sure it existed on the computer.

I removed the '1' and it works perfectly. Thanks alot.
Post Reply