简体   繁体   English

这个 PHP 警告“无法修改头信息”是什么?

[英]What is this PHP warning, “Cannot modify header information”?

I'm a newbie for PHP5 and In my php page I'm getting this error when try to redirect to another page我是 PHP5 的新手,在我的 php 页面中,尝试重定向到另一个页面时出现此错误

Warning: Cannot modify header information - headers already sent by (output started at <path to my php file>:<line number>) in <path to my php file> on line <line number>

in my php file I have several includes and each one doesnt have any space before of after tag在我的 php 文件中,我有几个包含,每个包含在标签之前和之后没有任何空间

This is because you must first set your headers and then add any output.这是因为您必须首先设置标题,然后添加任何输出。

If you did not echo/print anything make sure you did not have warnings or notices (the count as output too if you have error reporting on).如果您没有回显/打印任何内容,请确保您没有警告或通知(如果您有错误报告,也算作输出)。

As a good practice, if you can, put the header calls at the top of your script.一个好的做法是,如果可以的话,将标题调用放在脚本的顶部。

You could also take a look into output buffering if you need to generate output before headers.如果您需要在标题之前生成输出,您还可以查看输出缓冲。

Maybe your php file has a unicode signature (BOM) which adds a signature at the beginning of your file.也许您的 php 文件有一个 unicode 签名 (BOM),它会在您的文件开头添加一个签名。

open your php file with a plain text editor like notepad and see if there is something at the beginning of your file.使用记事本等纯文本编辑器打开您的 php 文件,看看文件开头是否有内容。 if so, remove them.如果是这样,请删除它们。

The problem could be an opening <?问题可能是开头<? tag with some spaces just before the "<" like shown here "_<".在“<”之前带有一些空格的标记,如此处所示的“_<”。 These spaces count as output and can prevent headers from being set.这些空格算作输出,可以防止设置标题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:无法修改标题信息,我的代码有什么问题 - Warning: Cannot modify header information, what is wrong in my code 警告:无法修改有关标题的标题信息 - Warning: Cannot modify header information about header WordPress-警告:无法修改标题信息 - WordPress - Warning: Cannot modify header information 警告:无法修改 header 信息 - Wordpress - Warning: Cannot modify header information - Wordpress PHP 重现警告“无法修改 header 信息 - 标头已由(输出开始于...”与 XAMPP 8..1.1 - PHP reproduce warning "Cannot modify header information - headers already sent by (output started at... " with XAMPP 8..1.1 关于警告的奇怪错误:无法修改标题信息-没有空格PHP时已经发送的标题 - Strange error regarding Warning: Cannot modify header information - headers already sent by when there is no white space PHP Wordpress提要:PHP警告无法修改标题信息-标题已发送 - Wordpress Feeds: PHP Warning Cannot modify header information - headers already sent PHP setcookie()给出“无法修改标题信息 - 标题已发送”警告 - PHP setcookie() gives “Cannot modify header information – headers already sent” warning Filemtime中的PHP警告()&无法修改标头信息 - 标头已发送错误 - PHP Warning in Filemtime() & Cannot modify Header information - Headers Already Sent Error PHP | Codeigniter重定向| 无法修改标题信息 - PHP | Codeigniter Redirect | Cannot modify header information
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM