Php 404找不到标题 [英] Php 404 Not Found Header

查看:176
本文介绍了Php 404找不到标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解3个简单的php代码行的组合,
这是代码:

  ob_end_clean(); 
header('HTTP / 1.0 404 Not Found');
出口;

所以这是代码,正如我理解的第一行 ob_end_clean() strong>,例如可以用 BOM(字节顺序标记)来帮助,所以第一行是防止任何以前的输出。



第二行标题('HTTP / 1.0 404 Not Found'); 是标题。 第三行 exit 终止脚本执行。



如果我删除第一行,并在文档中获得 BOM



如果我删除第三行(带或不带BOM),我就会看到我想要的页面没有空白页,也没有404。


  • Mabye如果任何人都可以解释为什么我应该使用出口
    404 header
    li>
  • 为什么使用物料清单我没有收到标题已发送错误



谢谢大家,祝你有美好的一天。

解决方案

如果我删除的第一行和我得到的文档BOM我得到空
页(404)。
你得到空白404,因为你没有在那里定义的内容...




  header('HTTP / 1.0 404 Not Found'); 

只会提示用户在404错误页面网站上...
如果您想要显示一些404通知给用户,你可以通过加载你的404.html文件来做到这一点



pre $ if(strstr($ _ SERVER [ 'REQUEST_URI'],'index.php')){
header('HTTP / 1.0 404 Not Found');
readfile('404missing.html');
exit();
}

或直接购买

  if(strstr($ _ SERVER ['REQUEST_URI'],'index.php')){
header('HTTP / 1.0 404 Not Found');
echo< h1>未找到错误404< / h1>;
回显找不到您请求的页面。;
exit();

$ / code>

退出函数存在是因为您必须阻止执行另一个php代码,可以直接在之后,如果或者稍后可以执行,简单地说 END


I am trying to understand the combination of 3 simple php code lines, This is the code:

ob_end_clean();
header('HTTP/1.0 404 Not Found');
exit;

So this is the code and as i understand the first line ob_end_clean();, Can help for example with BOM(Byte order mark), So the first line is to prevent any previous output.

The second line header('HTTP/1.0 404 Not Found'); is the header.

And the third line exit terminates the script execution.

If i remove the first line and i got a BOM at the document i get blank page (No 404).

If i remove the third line (with and without the BOM), I get the page i wanted no blank page and no 404.

  • Mabye if anyone can explain why should i use the exit After the 404 header
  • Also why with the BOM i dont get "headers already sent error"

Thank you all and have a nice day.

解决方案

If i remove the first line and i got a BOM at the document i get blank page (No 404). you get blank 404 because you have no content defined in there...

header('HTTP/1.0 404 Not Found');

is only giving notice that user is on 404 error page site... if you want to display some 404 notice for user you can do this by loading your 404.html file

if(strstr($_SERVER['REQUEST_URI'],'index.php')){
  header('HTTP/1.0 404 Not Found');
  readfile('404missing.html');
  exit();
}

or directly

if (strstr($_SERVER['REQUEST_URI'],'index.php')){
    header('HTTP/1.0 404 Not Found');
    echo "<h1>Error 404 Not Found</h1>";
    echo "The page that you have requested could not be found.";
    exit();
}

exit function is there because you have to prevent execution of another php code, which may be directly after if or which may be excecuted later, simply it says END

这篇关于Php 404找不到标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆