/[LeafOK_CVS]/fenglin/lib/client_addr.inc.php
ViewVC logotype

Diff of /fenglin/lib/client_addr.inc.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.9 by sysadm, Thu Jan 7 01:28:59 2010 UTC Revision 1.13 by sysadm, Tue Apr 29 11:55:32 2025 UTC
# Line 1  Line 1 
1  <?  <?php
2  require_once "common.inc.php";          require_once "../lib/ip_mask.inc.php";
3    
4  function Client_Address($addr=null,$x_addr=null)          function client_addr(int $mask_level = 0) : string
 {  
         global $SYS_proxy_ip;  
   
         $proxy_ip = $SYS_proxy_ip;  
   
         if ($addr == null)  
                 $addr = $_SERVER["REMOTE_ADDR"];  
   
         if ($x_addr == null && isset($_SERVER["HTTP_X_FORWARDED_FOR"]))  
                 $x_addr = $_SERVER["HTTP_X_FORWARDED_FOR"];  
   
         foreach($proxy_ip as $tmp => $ip)  
5          {          {
6                  if (preg_match("/".$ip."/",$addr))                  $ip = (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "");
                 {  
                         if ($x_addr != null)  
                         {  
                                 $client_addr = explode(",",$x_addr);  
                                 for($i=count($client_addr)-1;$i>=0;$i--)  
                                 {  
                                         $proxy = false;  
                                         foreach($proxy_ip as $tmp => $ip)  
                                         {  
                                                 if (preg_match("/".$ip."/",$client_addr[$i]))  
                                                         $proxy = true;  
                                         }  
                                         if (!$proxy)  
                                                 return trim($client_addr[$i]);  
                                 }  
                                 return trim($client_addr[0]);  
                         }  
                         else  
                         {  
                                 return $_SERVER["REMOTE_ADDR"];  
                         }  
                 }  
         }  
   
         return $_SERVER["REMOTE_ADDR"];  
 }  
7    
8  ?>                  return ip_mask($ip, $mask_level, "%");
9            }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1