Home  >  Article  >  Backend Development  >  用setCookie()时,将域名指定称“localhost”就保存不了Cookie咋回事?

用setCookie()时,将域名指定称“localhost”就保存不了Cookie咋回事?

WBOY
WBOYOriginal
2016-06-13 10:16:091807browse

用setCookie()时,将域名指定称“localhost”就保存不了Cookie怎么回事??
在本地测试的时候发现的。

这样可以设置Cookie:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    setCookie('name[1]', 'yy1', time() + 3600, '/');    setCookie('name[2]', 'yy2', time() + 3600, '/');


这样就不行了:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    setCookie('name[1]', 'yy1', time() + 3600, '/', 'localhost');    setCookie('name[2]', 'yy2', time() + 3600, '/', 'localhost');


这是为什么?设置称“localhost”不对吗???

谢谢!

------解决方案--------------------
when working on localhost the cookie-domain must be set to "" or NULL or FALSE
------解决方案--------------------
探讨

when working on localhost the cookie-domain must be set to "" or NULL or FALSE
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn