php 标头已发送错误
我有一个 php 文件,其中包含以下代码:
<?php header("Location: somepage.php"); ?>
在 php 开始或结束标记之前或之后绝对没有空格,并且我收到通常
Warning: Cannot modify header information - headers already sent by (output started at C:\ ... \test.php:1
当我收到此错误时,1 是问题的行号,但在此case 第一行没有任何额外的空格。我的页面上只有此代码,不包含任何其他文件。
我在 Windows XP 上使用 xampp。任何想法发生了什么或者我如何找出真正导致问题的原因。
谢谢
I have a single php file, with this code in it:
<?php header("Location: somepage.php"); ?>
Absolutely no spaces before or after the php opening or closing tags and I am getting the
Warning: Cannot modify header information - headers already sent by (output started at C:\ ... \test.php:1
Usually when I get this error, the 1 is the line number of the problem, but in this case line one doesn't have any extra whitespace. I only have this code on the page and I am not including any other files.
I'm using xampp on windows xp. Any ideas what's going on or how I can track down what's really causing the problem.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
文件中可能存在所谓的 BOM(字节顺序标记)。根据您使用的编辑器,您需要关闭添加 BOM...
Chances are that you have what's known as a BOM (Byte Order Mark) in the file. Depending on what editor you're using, you'll need to turn off adding the BOM...
尝试使用记事本将您的内容复制/粘贴到另一个新文件
Try to copy / paste your content to another new file using Notepad
尝试使用 WAMP,它不会显示此错误,请确保代码前后没有空格。为此,如果您使用的是记事本++或editplus,请转到格式并选择unix格式,一切应该可以正常工作。
或者
尝试将其放在页面顶部:
然后在页面底部放置此行代码:
Try using WAMP, it doesnt show this error, make sure you donot have spaces before or after the code. For that, if you are using notepad ++ or editplus, go to format and select unix formatting and things should work fine.
OR
try placing this at the top of your page:
then at the bottom of the page place this line of code:
如果您确定不是 BOM 导致错误,请检查您的 httpd.conf 和任何 .htaccess 文件(如果前置有任何其他文件)。留意类似这样的内容:
同时检查您的 PHP.ini: http://de.php.net/manual/en/ini.core.php#ini.auto-prepend-file
If you are sure it is not a BOM causing the error, check your httpd.conf and any .htaccess files if the prepend any other files. Look out for something like this:
Also check your PHP.ini: http://de.php.net/manual/en/ini.core.php#ini.auto-prepend-file