Simple cookie reading problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,  this is probably stupidly easy but I'm struggling.

I am trying to understand why cookies only appear to be readable when a
web page is retrieved by *typing the url into the browser's address
box* but NOT when the same page is accessed *via a link from another
page*.  I probably don't fully understand the mechanics of an HTTP


The first page sets a persistent cookie:

$value = 'something';
setcookie("TestCookie", $value, time()+(24*365*3600));

and contains a link - <a href="cookie_test.php?">Link to cookie

The second page [cookie_test.php] contains the following code:

print "COOKIE DATA: <br />";
foreach ( $_COOKIE as $cookie_name => $cookie_value ) {
    print "$cookie_name = $cookie_value <br />";

When a) viewing cookie_test.php, using either Firefox 2.0 or IE7, via
the link from page one, the cookie data does not print out.  But b) by
entering cookie_test.php into the address box and pressing return, this
causes the browser to display the cookie contents.
PHP Version 4.3.10

Could I have an explanation please and how do I retrieve cookie data in
case (a) ?

Thanks for your help...

Re: Simple cookie reading problem

Quoted text here. Click to load it

Hey 4site,
  Sounds like everything should work fine, but the browsers might be
caching cookie_test.php without the information on it. Have you tried
completely refreshing the page after cookie_test.php loads empty? You
might also check out the manual for header() as there is a good example
for stopping browsers from caching pages.
Good luck, Blayde

Site Timeline