2012-01-04 161 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