Localhost Cookie

…衆ロ難τιáo~ 提交于 2019-12-11 13:49:33

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/4845050/localhost-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!