Question

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

Was it helpful?

Solution

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;
}
?>

OTHER TIPS

Try if(isset($_SESSION['HTTP_REFERER'])) or if(empty($_SESSION['HTTP_REFERER']))

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top