Page 1 of 1

Help, I'm in Cookie hell !!!

Posted: Wed Mar 01, 2006 2:15 pm
by zeek
I have scripts setting and reading cookies. Everything works great on my server (Apache2, PHP4.4.0-3), but on my customer's server (Apache1.3.34 PHP4.4.1) the scripts can set the cookies fine, but can't read them. And, yes I know, I've learned my lesson - develop in a server with the same specs and config as the final server. In the mean time does anyone know what might be wrong? I'm using the code below to set and read the cookies...

Set cookie:

Code: Select all

setcookie("cust", $id, time()+60*60*2, '/');
Read cookie: (not working)

Code: Select all

$cust = $_COOKIE["cust"];
As per php.net's recommendation, I did a print_r($_COOKIE), and it doesn't show the cookie. The cookie is there though, because I can see it with Edit>Preferences>Privacy>View Cookies on my browser (Firefox). Thanks in advance for any help. Also, just a note, it's not a browser setting, because everything works great on my server with the same browser.

Posted: Wed Mar 01, 2006 2:36 pm
by neophyte
Didja try?

Code: Select all

$HTTP_COOKIE_VARS['cookiename'];

Posted: Wed Mar 01, 2006 2:38 pm
by feyd
Check to see if the cookie set in the browser on the set page. It may be an issue with the timeout you're using. For instance, the server may send a server time header in the response or the cookie sent may be in the past already for the browser. If you have Firefox and the Web Developer extension you can quickly check what headers were sent. You may need to set the domain part of the cookie.

Oops, didn't see the last part that says you see the cookie in the browser.


Make sure the domain and path are set correctly for the read and set pages.

That was it!!!

Posted: Wed Mar 01, 2006 3:24 pm
by zeek
feyd wrote:Make sure the domain and path are set correctly for the read and set pages.
That was it !!!! I never would have thought of setting the domain since everything is on the same domain, but I did it anyway and it fixed the problem! Turns out due to the way the links are created, the script setting the cookies was at http://www.mydomain.com, but the scripts reading were a just mydomain.com without the www.

Man thank you so much, I've spent hours on this. Thank you.