Reputation:
I have a php script that check if the referrer has been cleared after a short process, if it is it forwards to the destination, if it isn't blanked, the process I used for clearing the referrer restarts. It works so far, this is the code I used:
<?php
$referer = $_SERVER['HTTP_REFERER'];
if($referer == "")
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://sitetogoto.com\">";
}
else
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://sitewherereferrergetsclearedagain.com\">";
}
?>
This seems to work so far if I click a link that brings me to that script, it brings me to sitetogoto.com without a referrer. However, I have noticed when using an autosurf for example, I get stuck in an endless redirect where the referrer just doesn't clear... Any idea why?
Regards
Upvotes: 2
Views: 6108
Reputation: 544
Of course this doesn't work. the http referer is set in the browser, client side and not through the server.
Try to clear it using javascript
Upvotes: 0
Reputation: 36617
In PHP a clean way is a header redirection
<?php
if ($_SERVER['HTTP_REFERER']!="http://www.yoursite.com") {
header("Location: http://www.example.com/");
exit;
}
?>
Edit (Your Question)
<?php
if (!empty($_SERVER['HTTP_REFERER'])) {
// CLEAR IT / REDIRECT
header("Location: http://www.example.com/");
exit;
}
?>
Upvotes: 4
Reputation: 5478
Try if(isset($_SESSION['HTTP_REFERER']))
or if(empty($_SESSION['HTTP_REFERER']))
Upvotes: 0