php里面cookie的问题?狠奇怪
PHP code<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $value='something here'; setcookie("TestCookie",$value); setcookie("TestCookie",$value,time()+3600); echo $_COOKIE["TestCookie"]; echo "<br>"; echo $HTTP_COOKIE_VARS["TestCookie"]; echo "<br>"; print_r($_COOKIE); setcookie("cookie","ok");?>
最后一行放上去就报错如下:
Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\szxh2\comment\testcookie.php:5) in E:\xampp\htdocs\szxh2\comment\testcookie.php on line 10
刚弄不懂啊
------解决方案--------------------setcookie()是利用HTTP报头来发送cookie信息给浏览器端的,而HTTP报头必须位于实际内容之前输出。简而言之,setcookie(),header()之前不能有输出。
------解决方案--------------------cookie之前不能有任何输出。包括空格什么的
------解决方案--------------------必须在任何其他输出发送前对 cookie 进行赋值
------解决方案-------------------- Warning:说的很明白了。前面不能有输出
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