如何获取客户端ip

//获取客户端的ip
 function _getClientIp(){
           $unknown = 'unknown';
           if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown) ) {
                   $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
           } elseif ( isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown) ) {
                   $ip = $_SERVER['REMOTE_ADDR'];

           } else{
                   $ip = $unknown ;
           }
           return $ip ;
   }

 

posted on 2012-12-13 13:45  mingaixin  阅读(213)  评论(0编辑  收藏  举报