tags:

views:

33

answers:

1

So I have been working on a project for a client on their current web site which has been in existence for quite some time. The version of PHP used is 4.4.7, and I am not in a position to ask them to upgrade. (The system is old and it could break something) This past week I made some changes to my project, everything worked fine cookies set, pages worked. I go to test the site earlier and all of the sudden the cookies no longer work. After 2 hours of troubleshooting I finally just set up a simple test page composed of this:

<?php
setcookie('eventCookie','1', time()+7200,'/','.levijackson.net');
echo $_COOKIE['eventCookie'];
?>

I put this on both their site as well as my own (I changed the .levijackson.net to the appropriate domain)

I did 2 refreshes of the page on both pages and only on mine did it return the cookie. So what could have caused something like this? Is there a certain setting that may have been changed by their admin/host?

I did test and HttpOnly cookies still work, so I am going to switch to them while I troubleshoot.

edit: Almost forgot to mention, it works fine in FF but in Chrome and IE it doesn't work at all. Not sure if this will be useful, but I still think that it is not the browser.

Thanks
Levi

+2  A: 

Just a guess-- it could be that their server has auto_prepend_file enabled, and the file that is being auto-prepended outputs something to the client. Once anything is sent to the client, set_cookie() will not work, since cookies have to be set in the page header, which must be sent before anything is sent to the client.

If it's not that, try diff'ing the "PHP Core" section of a phpinfo() dump, looking for any other settings that might somehow affect this.

Edit: Here's something else you can try, if both sites are publicly accessible. Go here: http://web-sniffer.net/. This site will show you the actual HTTP headers which are being returned by the site. Run the test file for both sites, and look to see if there is any difference in the Set-Cookie headers which are returned.

Kip
phpinfo() says, 'auto_prepend_file no value no value'. I just ran though the rest and they are all the same. I also edited above, I don't know if it matters but FF works fine where as Chrome and IE do not. So perhaps it isn't the php? I am not sure how a browser could affect how php is processed?
Levi
The only difference I can see between the two headers is with php 4 it is sending 'expires=Wed, 30 Sep 2009 02:16:37' and with php 5 it sends 'expires=Wed, 30-Sep-2009 05:33:37'. From that I saw that my cookie was expiring as it was created... So weird, I am going to have to ask about it. Can you think of a reason the time would have changed?Anyway, thanks for the help!
Levi