public function ip($return_type = null, $ip_addresses = [])
  {
    $ip_elements = array(
      'HTTP_X_FORWARDED_FOR', 'HTTP_FORWARDED_FOR',
      'HTTP_X_FORWARDED', 'HTTP_FORWARDED',
      'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_CLUSTER_CLIENT_IP',
      'HTTP_X_CLIENT_IP', 'HTTP_CLIENT_IP',
      'REMOTE_ADDR'
    );

    foreach ( $ip_elements as $element ) {
      if(isset($_SERVER[$element])) {
        if ( !is_string($_SERVER[$element]) ) {
          // Log the value somehow, to improve the script!
          continue;
        }
        $address_list = explode(',', $_SERVER[$element]);
        $address_list = array_map('trim', $address_list);
        // Not using array_merge in order to preserve order
        foreach ( $address_list as $x ) {
          $ip_addresses[] = $x;
        }
      }
    }
    if (count($ip_addresses) == 0) {
      return false;
    } elseif ($return_type === 'array') {
      return $ip_addresses;
    } elseif ($return_type === 'single' || $return_type === null) {
      return $ip_addresses[0];
    }
  }
public function ip($return_type = null, $ip_addresses = [])
  {
    $ip_elements = array(
      'HTTP_X_FORWARDED_FOR', 'HTTP_FORWARDED_FOR',
      'HTTP_X_FORWARDED', 'HTTP_FORWARDED',
      'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_CLUSTER_CLIENT_IP',
      'HTTP_X_CLIENT_IP', 'HTTP_CLIENT_IP',
      'REMOTE_ADDR'
    );

    foreach ( $ip_elements as $element ) {
      if(isset($_SERVER[$element])) {
        if ( !is_string($_SERVER[$element]) ) {
          // Log the value somehow, to improve the script!
          continue;
        }
        $address_list = explode(',', $_SERVER[$element]);
        $address_list = array_map('trim', $address_list);
        // Not using array_merge in order to preserve order
        foreach ( $address_list as $x ) {
          $ip_addresses[] = $x;
        }
      }
    }
    if (count($ip_addresses) == 0) {
      return false;
    } elseif ($return_type === 'array') {
      return $ip_addresses;
    } elseif ($return_type === 'single' || $return_type === null) {
      return $ip_addresses[0];
    }
  }
public function ip ( $ return_type = null , $ ip_addresses = [ ] ) { $ ip_elements = array ( 'HTTP_X_FORWARDED_FOR' , 'HTTP_FORWARDED_FOR' , 'HTTP_X_FORWARDED' , 'HTTP_FORWARDED' , 'HTTP_X_CLUSTER_CLIENT_IP' , 'HTTP_CLUSTER_CLIENT_IP' , 'HTTP_X_CLIENT_IP' , 'HTTP_CLIENT_IP' , 'REMOTE_ADDR' ) ; foreach ( $ ip_elements as $ element ) { if ( isset ( $ _SERVER [ $ element ] ) ) { if ( ! is_string ( $ _SERVER [ $ element ] ) ) { // Log the value somehow, to improve the script! continue ; } $ address_list = explode ( ',' , $ _SERVER [ $ element ] ) ; $ address_list = array_map ( 'trim' , $ address_list ) ; // Not using array_merge in order to preserve order foreach ( $ address_list as $ x ) { $ ip_addresses [ ] = $ x ; } } } if ( count ( $ ip_addresses ) == 0 ) { return false ; } elseif ( $ return_type === 'array' ) { return $ ip_addresses ; } elseif ( $ return_type === 'single' || $ return_type === null ) { return $ ip_addresses [ 0 ] ; } }
Get client ip address

@return void
Get client ip address