Page 1 of 1

Cookies - either not saving or not reading correctly

Posted: Wed Jun 30, 2004 1:45 am
by TimM
Ok, having trouble now with cookies. Here's what I've got:

cookietest1.php

Code: Select all

<?php
setcookie("testcookie", "testvalue");
?>
<a href="cookietest2.php">click</a>
cookietest2.php

Code: Select all

<?php
print ($_COOKIE["testcookie"]);
?>
I was having trouble before this, and narrowed it down to the cookies, so I created these two files to try to figure out why it wasn't working. But, I'm stumped! I checked IE's privacy settings, even changed them to the lowest possible, and still no luck.

Basically what I've done is created cookietest1.php to set the cookie, then it has a link to cookietest2.php which reads the cookie. The output from cookietest2.php is just blank - as if the cookie had never been set. No errors or anything.

Is there something here I'm doing wrong, or is just my unlucky day?

Thanks

- Tim

Posted: Wed Jun 30, 2004 2:42 am
by Grim...
Does giving the cookie a time limit make any difference?

Posted: Wed Jun 30, 2004 5:08 am
by feyd
are you setting the cookie is a subfolder of the site, and trying to access it from a parent folder? (you may want to set the path argument)

Posted: Wed Jun 30, 2004 5:21 am
by JayBird
I think it would be an idea to see what is working - the setting or the reading.

Clear you IE cache and temp files. Run cookietest1.php and then check in the temp internet files to see wether the cookie has been created.

This will answer the above question, then we can concentrate on the part that actually isn't working.

Mark

Posted: Thu Jul 01, 2004 4:44 pm
by TimM
Well, what would you know, now it works..just like that! :roll:

Thanks Mark, that was a great idea. I was just doing that then when I realised that its now working. And I didn't change a thing.

Thanks anyway, everyone, for being willing to help out!

Cheers
Tim

Posted: Thu Jul 01, 2004 7:18 pm
by tim
Grim... wrote:Does giving the cookie a time limit make any difference?
If a time value isnt set, the cookie will delete as soon as the browser is closed.

hence why u should always set a time()

Posted: Thu Jul 01, 2004 7:28 pm
by TimM
If a time value isnt set, the cookie will delete as soon as the browser is closed.

hence why u should always set a time()
Unless you're using it to track a session - which is what's happening in this case :)

Posted: Thu Jul 01, 2004 8:41 pm
by tim
I know, it just seemed he was asking in general.