Reputation: 500
I have two files, checking.php contain code to check is it redirect from redirect.php, and print the corresponding message, redirect.php contain code to redirect to file A.
checking.php
$referrer = $_SERVER['HTTP_REFERER'];
if (!preg_match("/redirect.php/",$referrer)) {
echo 'not redirect from redirect.php';
}
else
{
echo 'is redirect from redirect.php';
}
redirect.php
header("location: http://abcdomain.com/checking.php");
exit();
But this is not working, please advice.
Upvotes: 0
Views: 121
Reputation: 1814
Using header("location: http://abcdomain.com/checking.php");
wont set REFERRER, one possible solution is shown below(tested and works 100% fine)
USE THIS IN REDIRECT.php
echo "<script>parent.self.location='http://abcdomain.com/checking.php';</script>";
exit();
This will set $_SERVER['HTTP_REFERER'] in checking.php
Possible Reasons for this problem shown below
Some browsers limit access to not allow HTTP_REFERER to be passed
Type a address in the address bar will not pass the HTTP_REFERER
open a new browser window will not pass the HTTP_REFERER, because HTTP_REFERER = NULL
has some browser addon that blocks it for privacy reasons.
Some firewalls and AVs do to.
Upvotes: 1
Reputation: 3171
Is it not redirecting at all for you, or redirecting, but printing the wrong message? If it's not redirecting, try "Location:" upper-case.
It if is redirecting try var_dump($_SERVER);
to see what is in it.
Upvotes: 0