原文链接:PHP Header用于页面跳转要注意的几个问题总结php技巧脚本之家
搜到了这篇文章,开头就说了三个关于PHP header()的注意事项,
- location和“:”号间不能有空格,否则会出错。
- 在用header前不能有任何的输出。
- header后的PHP代码还会被执行。
第3点测试结果无误。
第1点,测试大概是指的 header('Location: http://segmentfault.com/');
中 Location
和 :
不能有空格吧,但其实是可以有的。
主要是第2点,header前不能有任何的输出有疑问,我测试了下面的代码,能成功跳转啊:
<html>asdf</html>
<?php
header('Location : http://segmentfault.com/');
到底要怎样测试才能报错呢?php手册上的“Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP”到底是啥意思?
@scaret 应该是对的, 其实就是缓存的问题.
得到