/[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.3 by sysadm, Sun Jun 20 19:49:02 2004 UTC Revision 1.12 by sysadm, Wed Apr 23 05:13:57 2025 UTC
# Line 1  Line 1 
1  <?  <?php
2            require_once "../lib/ip_mask.inc.php";
3  function Client_Address()  ?>
4    <?php
5    function client_addr(int $mask_level = 0) : string
6  {  {
7          $proxy_ip = array(          $ip = (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "");
                 "^61.129.42.22[01]$",  
                 "^203.95.5.66$",  
                 "^10.85.31.[0-9]{1,3}$",  
                 "^192.168.176.57$"  
         );  
8    
9          foreach($proxy_ip as $ip)          return ip_mask($ip, $mask_level, "%");
         {  
                 if (ereg($ip,$_SERVER["REMOTE_ADDR"]))  
                 {  
                         if (isset($_SERVER["HTTP_X_CLIENT_ADDR"]))  
                         {  
                                 $client_addr = explode(",",$_SERVER["HTTP_X_CLIENT_ADDR"]);  
                                 for($i=count($_SERVER["HTTP_X_CLIENT_ADDR"])-1;$i>=0;$i--)  
                                 {  
                                         $proxy = false;  
                                         foreach($proxy_ip as $ip)  
                                         {  
                                                 if (ereg($ip,$_SERVER["REMOTE_ADDR"]))  
                                                         $proxy = true;  
                                         }  
                                         if (!$proxy)  
                                                 return trim($client_addr[$i]);  
                                 }  
                                 return trim($client_addr[0]);  
                         }  
                         else  
                         {  
                                 return $_SERVER["REMOTE_ADDR"];  
                         }  
                 }  
         }  
   
         return $_SERVER["REMOTE_ADDR"];  
10  }  }
   
11  ?>  ?>


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

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