function cleantalk_get_real_ip in Anti Spam by CleanTalk 8.4        
                          
                  
                        Same name and namespace in other branches
- 9.1.x src/lib/Cleantalk/Antispam/Cleantalk.php \Cleantalk\Antispam\cleantalk_get_real_ip()
1 call to cleantalk_get_real_ip()
  - Cleantalk::ct_session_ip in src/lib/Cleantalk/Antispam/Cleantalk.php
- Get user IP behind proxy server
File
 
   - src/lib/Cleantalk/Antispam/Cleantalk.php, line 755
Namespace
  Cleantalk\Antispam
Code
function cleantalk_get_real_ip() {
  
  $headers = function_exists('apache_request_headers') ? apache_request_headers() : $_SERVER;
  
  if (array_key_exists('X-Forwarded-For', $headers)) {
    $ip = explode(",", trim($headers['X-Forwarded-For']));
    $ip = trim($ip[0]);
  }
  elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers)) {
    $ip = explode(",", trim($headers['HTTP_X_FORWARDED_FOR']));
    $ip = trim($ip[0]);
  }
  else {
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  
  if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    $the_ip = $ip;
    
  }
  elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
    $the_ip = $ip;
    
  }
  else {
    $the_ip = null;
  }
  return $the_ip;
}