You are here

public function Cleantalk::ct_session_ip in Anti Spam by CleanTalk 8.3

Get user IP behind proxy server

File

src/lib/Cleantalk/Antispam/Cleantalk.php, line 604

Class

Cleantalk
Cleantalk class create request

Namespace

Drupal\cleantalk\lib\Cleantalk\Antispam

Code

public function ct_session_ip($data_ip) {
  if (!$data_ip || !preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/", $data_ip)) {
    return $data_ip;
  }

  /*if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

              $forwarded_ip = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);

              // Looking for first value in the list, it should be sender real IP address
              if (!preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $forwarded_ip[0])) {
                  return $data_ip;
              }

              $private_src_ip = false;
              $private_nets = array(
                  '10.0.0.0/8',
                  '127.0.0.0/8',
                  '176.16.0.0/12',
                  '192.168.0.0/16',
              );

              foreach ($private_nets as $v) {

                  // Private IP found
                  if ($private_src_ip) {
                      continue;
                  }

                  if ($this->net_match($v, $data_ip)) {
                      $private_src_ip = true;
                  }
              }
              if ($private_src_ip) {
                  // Taking first IP from the list HTTP_X_FORWARDED_FOR
                  $data_ip = $forwarded_ip[0];
              }
          }

          return $data_ip;*/
  return cleantalk_get_real_ip();
}