Why Sending a 404 Error in PHP May Not Work
In PHP, if you encounter an empty page despite using code to set a 404 Not Found header, it's because:
if (strstr($_SERVER['REQUEST_URI'],'index.php')) { header('HTTP/1.0 404 Not Found'); }
While technically correct, this code lacks a crucial step: PHP is responsible for outputting the 404 error page.
How 404s are Typically Handled
Normally, 404 errors are managed by the web server:
PHP's Role in Error Handling
However, when a PHP page is executed, the webserver passes control to PHP before it can handle a 404.
In this scenario, PHP lacks the capability to show a custom 404 page, resulting in a blank page. To resolve this issue, you can incorporate your desired 404 page within the PHP code or redirect to a dedicated 404 page that exists outside of the PHP application.
以上是為什麼我的 PHP 404 標頭會導致空白頁?的詳細內容。更多資訊請關注PHP中文網其他相關文章!