function detect real ip (updated)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GumSlone
    replied
    Originally posted by Anshul View Post
    is this will work on ngix wid mini opera nd proxies ??
    and last subnet 0 ?? isnt it wil return 0 in the last of all ip's ??
    yes it will return the last 0 for all ips,
    and it should work with nginx and opera and other proxies, this it the latest function which i am using on my sites,
    well,
    if you dont want to have the last number in ip =0;
    you can simply replace :
    PHP Code:
        list($ip1,$ip2,$ip3,$ip4) = explode('.',$ip); 
        return 
    $ip1.'.'.$ip2.'.'.$ip3.'.0'//REAL IP 
    by
    PHP Code:
    return $ip
    also if you dont use apache's mod_geo_ip for ip to coutry detection its better to set last ip value to zero and cache the result of geo ip detection for this ip eg. with memcached, this will reduce the server load.

    Leave a comment:


  • Anshul
    replied
    Originally posted by GumSlone View Post
    PHP Code:
    function gum_real_ip()
    {

        
    $keyname_ip_arr = array('HTTP_X_FORWARDED_FOR''HTTP_REMOTE_ADDR_REAL''HTTP_CLIENT_IP''HTTP_X_REAL_IP''REMOTE_ADDR');
        foreach (
    $keyname_ip_arr as $keyname_ip) {
            if (!empty(
    $_SERVER[$keyname_ip])) {
                
    $ip urlencode($_SERVER[$keyname_ip]);
                break;
            }
        }
        if (
    strstr($ip',')) {
            
    $ips explode(','$ip);
            
    $ip $ips[0];
        }
        if(empty(
    $ip)) $ip $_SERVER["REMOTE_ADDR"];
        
        list(
    $ip1,$ip2,$ip3,$ip4) = explode('.',$ip);
        return 
    $ip1.'.'.$ip2.'.'.$ip3.'.0'//REAL IP

    is this will work on ngix wid mini opera nd proxies ??
    and last subnet 0 ?? isnt it wil return 0 in the last of all ip's ??

    Leave a comment:


  • GumSlone
    started a topic function detect real ip (updated)

    function detect real ip (updated)

    PHP Code:
    function gum_real_ip()
    {
         
    $keyname_ip_arr = array('HTTP_X_FORWARDED_FOR''HTTP_REMOTE_ADDR_REAL''HTTP_CLIENT_IP''HTTP_X_REAL_IP''REMOTE_ADDR');
        foreach (
    $keyname_ip_arr as $keyname_ip) {
      if (!empty(
    $_SERVER[$keyname_ip])) {
       
    $ip $_SERVER[$keyname_ip];
       if (
    strstr($ip',')) {
        
    $ips explode(','$ip);
        foreach (
    $ips as $ip)
        {
          if(
    filter_var(trim($ip), FILTER_VALIDATE_IPFILTER_FLAG_NO_PRIV_RANGE)) break(2);
        }
       }
       elseif(
    filter_var($ipFILTER_VALIDATE_IPFILTER_FLAG_NO_PRIV_RANGE)) break;
      }
        }
        return 
    $ip;
        list(
    $ip1,$ip2,$ip3,$ip4) = explode('.',$ip);
        return 
    $ip1.'.'.$ip2.'.'.$ip3.'.0'//REAL IP

Working...
X