Simple cookie reading problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 4site

    #1

    Simple cookie reading problem

    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
    request...

    Example:

    The first page sets a persistent cookie:

    <?php
    $value = 'something';
    setcookie("Test Cookie", $value, time()+(24*365* 3600));
    ?>

    and contains a link - <a href="cookie_te st.php?">Link to cookie
    test</a>

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

    <?php
    print "COOKIE DATA: <br />";
    foreach ( $_COOKIE as $cookie_name =$cookie_value ) {
    print "$cookie_na me = $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...

  • Blayde

    #2
    Re: Simple cookie reading problem



    On Nov 5, 10:59 am, "4site" <ian4s...@hotma il.comwrote:
    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
    request...
    >
    Example:
    >
    The first page sets a persistent cookie:
    >
    <?php
    $value = 'something';
    setcookie("Test Cookie", $value, time()+(24*365* 3600));
    ?>
    >
    and contains a link - <a href="cookie_te st.php?">Link to cookie
    test</a>
    >
    The second page [cookie_test.php] contains the following code:
    >
    <?php
    print "COOKIE DATA: <br />";
    foreach ( $_COOKIE as $cookie_name =$cookie_value ) {
    print "$cookie_na me = $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...
    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

    Comment

    Working...