Forum Moderators: open

Message Too Old, No Replies

Cookies don't work in IE after server change

work in Firefox though

         

StoutFiles

10:55 pm on Jan 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I changed hosts to get my own dedicated server...and now IE won't use cookies with my site. Is there a way I can fix this? Code I've been using.

login.php:

$time = time();
setcookie('test', 'works', $time, '/', 'www.example.com');
if(isset($_COOKIE['test']))
{$visit = $_COOKIE['test'];}
else
{echo "Nope!";}
echo $visit;
?>

logout.php:

setcookie('test', works, time()-2592000, "/", "www.example.com");

eelixduppy

9:15 pm on Jan 15, 2009 (gmt 0)



I'm assuming this was working in IE before? Perhaps IE isn't accepting cookies from this new server. Try resetting your cookie preferences to make sure you aren't rejecting them. Also, the correct way to test to see if a cookie is set is if you can find it (on another page, perhaps) before the cookie expires. The fact that setcookie returns TRUE doesn't mean that the cookie was accepted by the user.

penders

2:28 pm on Jan 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$time = time();
setcookie('test', 'works', $time, '/', 'www.example.com');

I'm dubious whether this would ever work. $time should be a unix timestamp in the future (or 0 for a session cookie) - you are setting it to the current time (as set on the server) so it is likely to expire immediately unless your server time is running fast or your local machine is running slow!?

To allow your cookie to expire in 1 hour (60*60 = 3600 seconds), try:

$time = time() + 3600;

As eelixduppy suggests, I don't believe you can reliably test whether a cookie has actually been set on the same page you are setting the cookie (in PHP) - since a cookie is ultimately set on the local machine.