문제

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?

도움이 되었습니까?

해결책

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";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top