tags:

views:

756

answers:

4

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\"&gt;";
}
else
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://sitewherereferrergetsclearedagain.com\"&gt;";
}
?>

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

+5  A: 

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;
}
?>
Henrik P. Hessel
Yep, this is the way to do it.
Rich Bradshaw
hmm sounds like it would work. Just to check. I want it to check IF HTTP_REFERER is empty, it can continue. IF it contains anything, no matter what, it should clear it. Would that be possible?
loco41211
thank you! Trying it live now!
loco41211
A: 

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

usoban
A: 

Unfortunately, the above is wrong. A php header redirect will NOT clear the referrer.

HighTech
A: 

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

Svullo