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

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

WBOY
Release: 2016-06-13 13:38:22
Original
1149 people have browsed it

用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, '/');

Copy after login


这样就不行了:
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');

Copy after login


这是为什么?设置称“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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template