Professional Web Applications Themes

Cookie problems!! - PHP Development

I have a page with some cookie functionality. I set the cookie, and 'setCookie' returns true (=success). However 'print_r($_COOKIE)' shows that no cookies were set. I can set cookies with javascript just fine. This cookie-fumbling takes place before anything else (ie. before any output). I cant seem to find a solution - what to try next?...

  1. #1

    Default Cookie problems!!

    I have a page with some cookie functionality.

    I set the cookie, and 'setCookie' returns true (=success).

    However 'print_r($_COOKIE)' shows that no cookies were set.

    I can set cookies with javascript just fine. This cookie-fumbling takes
    place before anything else (ie. before any output).

    I cant seem to find a solution - what to try next?
    Jam Guest

  2. #2

    Default Re: Cookie problems!!

    Jam Pa said the following on 13/06/2005 15:56: 

    $_COOKIE[] only holds the cookie variables that have been *sent* from
    the user's browser. Therefore if you call setCookie(), you won't see
    anything in $_COOKIE[] until after the user refreshes (or moves to
    another page on your site).


    --
    Oli
    Oli Guest

  3. #3

    Default Re: Cookie problems!!

    Jam Pa wrote: 

    It's as Oli said, but to supplement.
    PHP is server side only. That means when you tell the php compiler to
    make a page, the page is processed (and in this case the cookie is set
    on the client side). Once the page has been processed PHP has absolutely
    no access to it until a reload. That means it can't read the cookie off
    the client until a refresh is done, at that point the cookies will be
    sent up with the browser request (i.e. the browser sends "give me this
    page: .. the referrer is: .. the client is: .. I have the following
    cookies set for this domain: ..) etc etc.

    Javascript OTOH is client side, meaning it can set a cookie after the
    page has loaded, and it can revoke that cookie after the page has
    loaded, in fact it can do anything after the page has loaded without the
    need for a refresh.
    Chris Guest

  4. #4

    Default Re: Cookie problems!!

    I know that the page content is only retreieved once. Before the next
    refresh that is.

    But the cookie is not set. COOKIE NOT SET WITH setCookie. :)

    Please read the posts you reply to more carefully.
    Jam Guest

  5. #5

    Default Re: Cookie problems!!

    Jam Pa said the following on 13/06/2005 16:45: 

    Yes, but when/how did you check?
     

    I believe he did.

    --
    Oli
    Oli Guest

  6. #6

    Default Re: Cookie problems!!

    Jam Pa wrote: 


    I did read it carefully.

    Your claim that was you set a cookie, then did print_r($_COOKIE) and it
    came back blank, which it would because the page is sent to the browser
    with a "set this cookie" instruction. After the page is sent, PHP has
    absolutely no control over it until you refresh meaning you can't say
    "retrieve the cookie" because it can't.. or at least it can but as the
    cookie hasn't been set yet it will come back blank.

    If your complaint, however, is that AFTER a refresh the cookie is not
    showing up, then you need to write more clearly. If this is the case you
    will need to show us the first few lines of your code.
    Chris Guest

Similar Threads

  1. Cookie Problems
    By in forum ASP
    Replies: 4
    Last Post: July 1st, 01:04 AM
  2. FormsAuthentication cookie problems
    By Scott in forum ASP.NET Security
    Replies: 0
    Last Post: October 3rd, 07:44 PM
  3. Replies: 7
    Last Post: September 5th, 06:28 PM
  4. authentication cookie vs session cookie
    By Joseph in forum ASP.NET Security
    Replies: 4
    Last Post: August 12th, 10:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139