为什么我的 PHP 应用程序不会发送 404 错误? [英] Why won't my PHP app send a 404 error?

查看:27
本文介绍了为什么我的 PHP 应用程序不会发送 404 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

为什么这不起作用?我得到一个空白页.

Why wont this work? I get a blank page.

推荐答案

您的代码在技术上是正确的.如果您查看该空白页的标题,您会看到 404 标题,其他计算机/程序将能够正确地将响应识别为未找到文件.

Your code is technically correct. If you looked at the headers of that blank page, you'd see a 404 header, and other computers/programs would be able to correctly identify the response as file not found.

当然,您的用户仍然是 SOL.通常,404 由 Web 服务器处理.

Of course, your users are still SOL. Normally, 404s are handled by the web server.

  • 用户:嘿,在这个 URI 网络服务器上有什么要给我的吗?
  • 网络服务器:不,我不知道,404!这是一个显示 404 的页面.

问题是,一旦网络服务器开始处理 PHP 页面,它就已经过了处理 404 的点

The problem is, once the web server starts processing the PHP page, it's already passed the point where it would handle a 404

  • 用户:嘿,在这个 URI 网络服务器上有什么要给我的吗?
  • Webserver:是的,我知道,这是一个 PHP 页面.它会告诉你响应代码是什么
  • PHP:嘿,天哪 404!!!!!!!
  • Webserver: 废话,404 页面的人已经回家了,所以我将 PHP 提供的任何内容发送出去

除了提供 404 标头之外,PHP 现在还负责输出实际的 404 页面.

In addition to providing a 404 header, PHP is now responsible for outputting the actual 404 page.

这篇关于为什么我的 PHP 应用程序不会发送 404 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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