PHP代码:得到客户端的IP
程序员文章站
2022-04-06 11:19:55
...
function get_client_ip()
{
if(getenv('HTTP_CLIENT_IP'))
{
$client_ip = getenv('HTTP_CLIENT_IP');
}
elseif(getenv('HTTP_X_FORWARDED_FOR'))
{
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif(getenv('REMOTE_ADDR'))
{
$client_ip = getenv('REMOTE_ADDR');
}
else
{
$client_ip = $HTTP_SERVER_VAR['REMOTE_ADDR'];
}
return $client_ip;
}
{
if(getenv('HTTP_CLIENT_IP'))
{
$client_ip = getenv('HTTP_CLIENT_IP');
}
elseif(getenv('HTTP_X_FORWARDED_FOR'))
{
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif(getenv('REMOTE_ADDR'))
{
$client_ip = getenv('REMOTE_ADDR');
}
else
{
$client_ip = $HTTP_SERVER_VAR['REMOTE_ADDR'];
}
return $client_ip;
}