setcookie()不在Internet Explorer或safari中工作

I had the following code:

setcookie('username', $email, false, 'affiliates/', 'www.mydomain.com');

It wasn't working in IE or Safari. Then I changed it to:

setcookie('username', $email, time()+60*60*24, 'affiliates/', 'www.mydomain.com');

And it started working. Now, 2 days later, it doesn't work again. I don't think I changed anything. The setting of the cookie is being checked in another file, with this code:

if( isset($_COOKIE['username']) ) {
    ...
}
else {
    print( "<meta HTTP-EQUIV='REFRESH' content='0; url=index.html'>" );
    exit();
}

It always redirects to index.html (in Safari and IE). Any ideas why this would cease to work? (I've made sure cookies are enabled in both browsers).

One thing I did during the time it stopped working was test the site running on localhost. I changed the code to:

setcookie('username', $email, time()+60*60*24, 'affiliates/', null);

But only for the localhost version.

Are you sure you have setcookie before all the other output? Headers can't be set after any like text or html. Maybe you need to remove any space above your

Also, the cookie must be set and used from the same domain and path.