You are here

public function CleanTalkSFW::cleantalk_get_real_ip in Anti Spam by CleanTalk 7.2

File

./cleantalk.module, line 29
Main CleanTalk integration module functions.

Class

CleanTalkSFW
Cleantalk Spam FireWall class

Code

public function cleantalk_get_real_ip() {
  if (function_exists('apache_request_headers')) {
    $headers = apache_request_headers();
  }
  else {
    $headers = $_SERVER;
  }
  if (array_key_exists('X-Forwarded-For', $headers)) {
    $the_ip = explode(",", trim($headers['X-Forwarded-For']));
    $the_ip = trim($the_ip[0]);
    $this->ip_str_array[] = $the_ip;
    $this->ip_array[] = sprintf("%u", ip2long($the_ip));
  }
  if (array_key_exists('HTTP_X_FORWARDED_FOR', $headers)) {
    $the_ip = explode(",", trim($headers['HTTP_X_FORWARDED_FOR']));
    $the_ip = trim($the_ip[0]);
    $this->ip_str_array[] = $the_ip;
    $this->ip_array[] = sprintf("%u", ip2long($the_ip));
  }
  $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
  $this->ip_str_array[] = $the_ip;
  $this->ip_array[] = sprintf("%u", ip2long($the_ip));
  if (isset($_GET['sfw_test_ip'])) {
    $the_ip = $_GET['sfw_test_ip'];
    $this->ip_str_array[] = $the_ip;
    $this->ip_array[] = sprintf("%u", ip2long($the_ip));
  }
}