I have a PHP script that does some validation, and if the validation is off, it should return 404. But it doesn’t.
Here is the beginning of the script:
<?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: problem_url_error@problemio.com";
$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');
}
But for some reason, this does not return a 404 – any idea why?
Thanks!!
The header is called status:
EDIT:
Now I see your approach should work as well, study the header documentation if you meet the requirements to use
header("HTTP/xxx ..."), there are some limitations.