php获取真实用户ip

 1 /**
 2      * 获取用户真实IP
 3      * @return $onlineIp
 4      */
 5     public function getOnlineIp()
 6     {
 7         if (getenv('HTTP_CLIENT_IP')) {
 8             $onlineIp = getenv('HTTP_CLIENT_IP');
 9         } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
10             $onlineIp = getenv('HTTP_X_FORWARDED_FOR');
11         } elseif (getenv('REMOTE_ADDR')) {
12             $onlineIp = getenv('REMOTE_ADDR');
13         } else {
14             $onlineIp = 'unknown';
15         }
16         return $onlineIp;
17     }

 

posted @ 2016-04-27 12:17  多多喜  阅读(291)  评论(0编辑  收藏  举报