为什么我的PHP应用程序不会发送404错误? [英] Why won't my PHP app send a 404 error?
问题描述
if(strstr($ _ SERVER ['REQUEST_URI'],'index.php')){
header('HTTP / 1.0 404 Not Found');
}
为什么不做这项工作?我得到一个空白页面。
您的代码在技术上是正确的。如果您查看了该空白页面的标题,则会看到一个404标题,其他计算机/程序将能够正确识别未找到文件的响应。
<当然,你的用户仍然是SOL。通常,404由Web服务器处理。
- 用户:嘿,你对这个URI web服务器有任何帮助吗?
- 不,我没有,404!这是一个404页面显示的页面。
问题是,一旦Web服务器开始处理PHP页面,它已经通过了点它将处理一个404
- 用户:嘿,你对这个URI web服务器有任何帮助吗?
- Webserver:是的,我确实是一个PHP页面。它会告诉你响应代码是什么
- PHP:嘿,OMG 404 !!!!!!!
- Webserver: 404页面的人已经回家了,所以我只会发送任何PHP给我
除了提供404头,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.
解决方案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.
Of course, your users are still SOL. Normally, 404s are handled by the web server.
- User: Hey, do you have anything for me at this URI webserver?
- Webserver: No, I don't, 404! Here's a page to display for 404s.
The problem is, once the web server starts processing the PHP page, it's already passed the point where it would handle a 404
- User: Hey, do you have anything for me at this URI webserver?
- Webserver: Yes, I do, it's a PHP page. It'll tell you what the response code is
- PHP: Hey, OMG 404!!!!!!!
- Webserver: Well crap, the 404 page people have already gone home, so I'll just send along whatever PHP gave me
In addition to providing a 404 header, PHP is now responsible for outputting the actual 404 page.
这篇关于为什么我的PHP应用程序不会发送404错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!