<?php
//客户端IP
function get_client_ip()
{
if(getenv('HTTP_CLIENT_IP'))
{
$client_ip = getenv('HTTP_CLIENT_IP');
}
else if(getenv('HTTP_X_FORWARDED_FOR'))
{
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
}
else if(getenv('REMOTE_ADDR'))
{
$client_ip = getenv('REMOTE_ADDR');
}
else
{
$client_ip = $HTTP_SERVER_VAR['REMOTE_ADDR'];
}
return $client_ip;
}
//服务器IP
function get_server_ip()
{
if(isset($_SERVER))
{
if($_SERVER['SERVER_ADDR'])
$get_ip = $_SERVER['SERVER_ADDR'];
else
$get_ip = $_SERVER['LOCAL_ADDR'];
}
else
{
$get_ip = getenv('SERVER_ADDR');
}
return $get_ip;
}
echo get_client_ip();
echo get_server_ip();
?>
PHP获取客户端和服务器的IP地址
最新推荐文章于 2021-03-28 22:51:29 发布