简体   繁体   中英

Redirecting to 404 page

I have the following code in a PHP script:

<?php

if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
    die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

// Other statements follow here
echo 'Hello there ...'

instead of echoing the message, I want to redirect the user to a 404 page. However, when I replace the die() statement with this one:

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

A user running the script from a remote machine is able to see the message 'Hello there ...'

How can I get the page to redirect to 404 page for non-localhost requests for the script?

BTW, this snippet id from the dev environment front controller in the Symfony framework.

It should be:

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

You need to put the exit(); to avoid that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM