Help - Search - Member List - Calendar
Full Version: Cookie problems!!
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
Jam Pa
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 Pa
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.

Oli Filth
Jam Pa said the following on 13/06/2005 15:56:
QUOTE
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.


$_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

Chris B
Jam Pa wrote:
QUOTE
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?

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.

Oli Filth
Jam Pa said the following on 13/06/2005 16:45:
QUOTE
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. :)


Yes, but when/how did you check?

QUOTE
Please read the posts you reply to more carefully.

I believe he did.

--
Oli

Chris B
Jam Pa wrote:
QUOTE
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.


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.


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.