Why won#39;t my PHP app send a 404 error?(为什么我的 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 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我的 PHP 应用程序不会发送 404 错误?


- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01