ip 获取

<?php
    class getIP{   
     function clientIP(){   
      $cIP = getenv('REMOTE_ADDR');   
      $cIP1 = getenv('HTTP_X_FORWARDED_FOR');   
      $cIP2 = getenv('HTTP_CLIENT_IP');   
      $cIP1 ? $cIP = $cIP1 : null;   
      $cIP2 ? $cIP = $cIP2 : null;   
      return $cIP;   
     }   
     function serverIP(){   
      return gethostbyname($_SERVER["SERVER_NAME"]);   
     }   
    }   
        
    $getIP  = new getIP();   
    $clientIp = getIP::clientIP();   
    $serverIp = getIP::serverIP();   
        
    echo 'Client IP is ',$clientIp,'<br />';   
    echo 'Server IP is ',$serverIp,'<br />';  

?>

posted @ 2014-11-19 21:56  lemon66  阅读(156)  评论(0编辑  收藏  举报