Cookies not being set...Why?

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
arctictiger
Forum Newbie
Posts: 4
Joined: Mon Oct 24, 2005 5:47 pm

Cookies not being set...Why?

Post by arctictiger »

Hi,

I'm fairly new to php so please be patient with me if this is a stupid ass question.

I'm trying to get my site to set a cookie using this code:

Code: Select all

<?php 
setcookie("uname", $name, time()+36000);
?>

<html>
<body>

<p>
A cookie was set on this page! The cookie will be active when 
the client has sent the cookie back to the server.
</p>

</body>
</html>
All well and good as this is a tutorial from w3schools.com however this code has worked once, but then I tried to impliment it into my site and it no longer works, so I went back to try and use just that code again and now it doesn't work at all. No cookie is being set with that code and I was wondering if anyone know what the problem might be.

Cheers
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

1. Is your browser set to accept cookies?
2. Have you cleared your browsers cache?
3. How are you testing for the set cookie?
arctictiger
Forum Newbie
Posts: 4
Joined: Mon Oct 24, 2005 5:47 pm

Re: Cookies not being set...Why?

Post by arctictiger »

1. Yeah
2. Yeah
3. Running the script from my site then checking in my cookies folder on my machine.

All other sites leave cookies on my machine but that script wont work for some reason. :oops:
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Post by someberry »

How are you testing to see if the variable is set? It should be:

Code: Select all

$_COOKIE['uname']
If that doesn't work, try clearing the cookie doing something like:

Code: Select all

setcookie("uname", $name, time()-1000);
And then trying again. Remember that you cannot use the cookie on the same page at the time you created it.
arctictiger
Forum Newbie
Posts: 4
Joined: Mon Oct 24, 2005 5:47 pm

Post by arctictiger »

Nope, this has no affect at all.

I'm sorry to bother you with this, must be something happening with my server. :cry:
arctictiger
Forum Newbie
Posts: 4
Joined: Mon Oct 24, 2005 5:47 pm

Post by arctictiger »

:oops:
Ok I'm a comlete and utter n00b.
Somehow firefox had blocked my site. I feel like such a tit.

Plentiful amounts of flamming will be appreciated.

Sorry to waste your time
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Sometime's the must irritating problems have to simplest solutions ;) Glad you got it sorted :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

arctictiger wrote::oops:
Ok I'm a comlete and utter n00b.
Somehow firefox had blocked my site. I feel like such a tit.

Plentiful amounts of flamming will be appreciated.

Sorry to waste your time
It has happened to all of us at some point. Glad to see you figured it out.
Post Reply