setcookie 的问题
有一个想法,无论如何我都无法理解:((( 当我尝试设置cookie(位于login.php中的第28行)时,浏览器返回一个错误!
无法修改标头信息 - 标头已由第 28 行 C:\xampp2\htdocs\video\login.php 中的(输出从 C:\xampp2\htdocs\video\index.php:9 开始)发送
无法修改标头信息 - 已由 C:\xampp2\htdocs\video\login.php 中第 28 行但索引中第 9 php,我没有任何标题!有一个标签!!!
我听不懂!有人能告诉我为什么它会返回这样的错误吗?
there is one think, i can't understand anyway:(((
when i try to set cookie(it is on line 28 in login.php), browser returns me an error!!!
Cannot modify header information - headers already sent by (output started at C:\xampp2\htdocs\video\index.php:9) in C:\xampp2\htdocs\video\login.php on line 28
but on line 9 in index php, i haven't any header!!! there is a tag!!!
i cant understand it!!! can somebody tall me why it returns me such error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Cookie 作为标头发送。来自 setcookie 的 PHP 文档:
此外,如果您的页面以 UTF-8 格式保存,BOM(字节顺序标记)将阻止您设置任何标头,因为它算作输出。请参阅http://bugs.php.net/bug.php?id=22108。为了解决这个问题,您需要保存不带字节顺序标记的文件。
另请参阅:字节顺序标记#Unwanted BOM - 维基百科
Cookies are sent as headers. From the PHP docs for setcookie:
Also, if your page is saved in UTF-8 format, the BOM (Byte Order Mark) will stop you from being able to set any headers, as it counts as output. See http://bugs.php.net/bug.php?id=22108. To get around this you need to save your file without the byte order mark.
See also: Byte order mark#Unwanted BOMs - Wikipedia
在发送标头之前,您无法打印网站上的任何内容。
You can't print out anything on the site before sending a Header.
首先在任何 html 标签(也称为输出)之前设置 cookie,甚至在声明 !DOCTYPE html 或 head、标头信息等之前。例如你的文件可能看起来像:
set the cookie first before any html tags (a.k.a output), even before declaring !DOCTYPE html or head, header information and the like. for example your file could look something like:
请发布一些代码。
此错误的含义是,某些内容已经发送(也可以是回显、错误通知等)。
Please post some code.
What this error means is, that something was already sent (can also be an echo, error notice etc.).
您必须将标头函数放在应用程序的最顶部。基本上第一行是 header();
You have to have your header functions at the very top of your application. Like basically the first lines are for header();