Help, I'm in Cookie hell !!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

Help, I'm in Cookie hell !!!

Post 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.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Didja try?

Code: Select all

$HTTP_COOKIE_VARS['cookiename'];
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

That was it!!!

Post 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.
Post Reply