Location: PHPKode > projects > Esvon Personals > esvon-personals/inc/funcs/alt_remote_addr.php
<?php

function alt_remote_addr (){

  if(!$_SERVER['HTTP_X_FORWARDED_FOR']) return;

  static $alt_ip;
  if(!isset($alt_ip)){

  	$priv_masks = array('10.', '192.168.', '127.', '172.16.0.', 'unknown');
    $ips = str_replace(' ','',$_SERVER['HTTP_X_FORWARDED_FOR']);
    $ips = array_reverse(explode(',',$ips));
    foreach(array_values($ips) as $k=>$ip){
      foreach($priv_masks as $pip) {
         if(strpos($ip, $pip) === 0) { // local ip
           if(count($ips)>1) unset($ips[$k]);
           break;
         }
       }
    }
    $ip = array_shift($ips);
    //$ip_oct = '(?:(?:\d{1,2})|(?:1\d{2})|(?:2[0-4]\d)|(?:25[0-5]))'; // precise IP validation
    $ip_oct = '\d{1,3}';
    if(!preg_match('/^(?:'.$ip_oct.'\.){3}'.$ip_oct.'$/', $ip)) die("IP resolving failed: $ip");
    $alt_ip = $ip;

  }
  
  return $alt_ip;

}

?>
Return current item: Esvon Personals