You are here

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

Same name and namespace in other branches
  1. 7.5 src/Cleantalk.php \Cleantalk::ct_session_ip()
  2. 7 cleantalk.module \Cleantalk::ct_session_ip()
  3. 7.4 src/Cleantalk.php \Cleantalk::ct_session_ip()

Get user IP behind proxy server

File

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

Class

Cleantalk
Cleantalk class create request

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();
}