当前位置: 老葡京网站娱乐 > web开发 > PHP > 正文

PHP获取用户的真实IP地址

时间:2017-04-08 CSDN博客 Coder_Designer
 老葡京网站娱乐 www.sdguanhua.com 
<?php

function getRealIpAddr() 
{ 
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) 
    { 
        $ip=$_SERVER['HTTP_CLIENT_IP']; 
    } 
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) 
//to check ip is pass from proxy 
    { 
        $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; 
    } 
    else 
    { 
        $ip=$_SERVER['REMOTE_ADDR']; 
    } 
    return $ip; 
} 

echo getRealIpAddr();

?>