Huseyin
Huseyin

Reputation: 1527

Localhost Cookie

I am using PHP under localhost (XAMPP). I am trying to set a cookie with .localhost as its domain.

setcookie($key, $value, $expire, $path, '.localhost', $secure, $httponly);

Because of multiple subdomains on real sites. It works by Firefox But it fails by IE8. I can restrict it by PHP coding then it would be neglected if localhost is as server domain. But I am not sure that whether cause many problems on real site servers? Can I use it on real servers? .example.com without www. prefix might cause same problems? Is there any hack for this case?

Upvotes: 1

Views: 3623

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318698

Setting a cookie for .localhost makes no sense.

Simply check if the domain is 'localhost' and in this case do not add a leading dot. Otherwise, '.domain.tld' is fine to set it for the domain and all its subdomains (most browsers handle cookies set for 'domain.tld' in the same way btw, but the RFC requires a leading dot).

Upvotes: 3

Related Questions