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 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
