2012-01-04 159 views
1

我有一个PHP脚本来做一些验证,如果验证关闭,它应该返回404。但它没有。脚本没有返回404

下面是脚本的开头:

<?php 
include '../connect.php'; 
include '../global.php'; 
include '../utils/api/problems.php'; 
include '../utils/api/suggested_solutions.php'; 
include '../utils/api/attempted_solutions.php'; 
include '../utils/api/categories.php'; 

$problem_id = mysql_real_escape_string($_GET["problem_id"]); 

// Get member_id from session 
$member_id = $_SESSION['user_id']; 

// Validate the call 
if (empty ($problem_id) || !isset ($problem_id) || !is_numeric ($problem_id)) 
{ 
    $referer = $_SERVER['HTTP_REFERER']; 

    // Send me an email with the error: 
    $from = "from: [email protected]"; 
    $to_email_address = 'my_email'; 
    $error_subject = 'Error happened when getting problem_id from request'; 
    $contents = 'Error in problem.php - here is the referer: '.$referer; 

    //mail($to_email_address, $error_subject, $contents, $from);  

    error_log (".......error validating problem id in problem.php"); 
    header('HTTP/1.1 404 Not Found'); 
} 

但出于某种原因,这并不返回404 - 任何想法,为什么?

谢谢!

+0

什么** **并使其返回?一个空白页面的任何机会? – ManseUK 2012-01-04 17:33:42

+0

你打开了display_errors吗?你不知道有关已经发送的头文件的错误吗? – Hossein 2012-01-04 17:37:31

回答

4

头被称为状态:

header("Status: 404 Not Found"); 

编辑: 现在我明白你的做法应该工作为好,学习头documentation如果您符合要求,使用header("HTTP/xxx ..."),也有一些限制。使用FastCGI当状态报头用于 - - Docs

3
header("HTTP/1.0 404 Not Found"); 

应根据该文档是足够的。

你将得到的是一个空白页面,您可以添加的内容是这样的:

header("HTTP/1.0 404 Not Found"); 
echo "<h1>404 Not Found</h1>"; 
echo "The page that you have requested could not be found."; 
+0

出于某种原因,没有头文件工作。我不知道为什么。 :( – GeekedOut 2012-01-04 18:22:21

+0

也许还有一些其他的头文件已经发送 - 请在设置头文件之前查看“headers_sent()”返回的内容 – ManseUK 2012-01-05 08:35:55