PHP获取用户的真实IP

获取用户的真实  IP

function getRealIpAddr() 
{ 
    if (!emptyempty($_SERVER['HTTP_CLIENT_IP'])) 
    { 
        $ip=$_SERVER['HTTP_CLIENT_IP']; 
    } 
    elseif (!emptyempty($_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; 
}

语法:

<?php
$ip = getRealIpAddr();
echo $ip;
?>

分类:
|  标签 :
0 0 vote
Article Rating
Subscribe
提醒
guest
0 评论
Inline Feedbacks
View all comments