PHP发送header头404信息
其实很简单,直接上代码再解释。
if ( stripos(php_sapi_name(),'cgi') === 0 ) { @header('Status: 404 Not Found',true); } else { @header( (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1').' 404 Not Found'); } echo <<<EOD <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL was not found on this server.</p> </body></html> EOD; exit;
其实正常情况下只需要header(‘HTTP/1.1 404 Not Found’)即可,但看到一个https://bugs.php.net/bug.php?id=27345,英语不是很好,好像CGI模式就是用Status进行发送的。
标签:header, HTTP, PHP