Pregunta

I have been hit with a huge amount of traffic recently from proxy visitors and countries that are not within the target demographics from the site (flat out visitors from these countries cannot use the service).

Rather than simply blocking the visitors, I want to not render the Google Analytics and other analytics code for these visitors. This seems to be a happy medium vs just whacking everything coming in, but I'm not sure of the best way to detect proxy visitors. What is the preferred method for detecting proxy visitors and visitors that fit within certain geographical IP boundaries?

¿Fue útil?

Solución

Just run this function to detect if proxy is used, and if so, you can use whatever analytics code you want or block the user.

function proxy_detected()
{
  if (
     $_SERVER['HTTP_X_FORWARDED_FOR']
  || $_SERVER['HTTP_X_FORWARDED']
  || $_SERVER['HTTP_FORWARDED_FOR']
  || $_SERVER['HTTP_CLIENT_IP']
  || $_SERVER['HTTP_VIA']
  || in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554))
  || @fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 30))
  {
      return true;
  } else {
      return false;
  }
}

echo ( proxy_detected() ) ? "Proxy detected" : "No proxy detected";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top