本地主机Cookie [英] Localhost Cookie

查看:173
本文介绍了本地主机Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在localhost(XAMPP)下使用PHP。
我试图设置一个以.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);

由于实际网站上有多个子网域。
它的工作原理是Firefox但它失败的IE8。
我可以通过PHP编码限制它,否则如果localhost作为服务器域将被忽略。
但是我不确定是否在真实站点服务器上引起很多问题?我可以在真实的服务器上使用它吗? .example.com(不含www)。前缀可能会导致同样的问题?

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?

推荐答案

.localhost设置cookie 没有意义。

只需检查域是否为localhost,在这种情况下不要添加前导点。
否则,'.domain.tld'可以为域及其所有子域设置它(大多数浏览器都以相同的方式处理cookie为domain.tld设置btw,但 RFC 需要一个前导点)。

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

这篇关于本地主机Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆