I don't want to allow users to type the URLs manually in web browser. It may lead to hacking attacks. So if the http referer is empty, it should redirect to home page.
I write this php code in drupal web application's index.php.
if($_SERVER["HTTP_REFERER"] == "")
{
header("Location:http://mysite.com");
}
The problem is that the loop continues infinitely. It never shows the home page. $_SERVER["HTTP_REFERER"] is always empty.
In Firefox, I get the below error. The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
How to resolve it?
Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
php.net/manual/en/reserved.variables.server.php