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

+0

display_errorsをオンにしましたか?すでに送信されたヘッダーなどについて何かエラーはありませんか?何らかの理由で – Hossein

答えて

4

ヘッダは、ステータスと呼ばれている:

header("Status: 404 Not Found"); 

EDIT: は今、私はあなたがheader("HTTP/xxx ...")を使用するための要件を満たしている場合も同様仕事、ヘッダdocumentationを勉強する必要があり、あなたのアプローチを参照して、そこにあるいくつかの限界。

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

はドキュメントに従って十分であるべきである - Docs - のFastCGIを使用するときにステータスヘッダが使用されます。 ** **それは返さない何

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

+0

おそらく他のいくつかのヘッダがすでに送られています - あなたのヘッダを設定する直前に 'headers_sent()'が何を返すかを見てください – ManseUK

関連する問題