Home >Backend Development >PHP Tutorial > php里面cookie的有关问题?狠奇怪

php里面cookie的有关问题?狠奇怪

WBOY
WBOYOriginal
2016-06-13 13:43:28950browse

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
Previous article: 关于ajax,该怎么处理 Next article: mysql分表怎么办