获取访问者的 客户端IP地址
程序员文章站
2022-05-02 08:29:15
...
/** * 获取访问者的 客户端的ip地址
if ($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif ($_SERVER['REMOTE_ADDR']){
$ip = $_SERVER['REMOTE_ADDR'];
}elseif (getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
}elseif (getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}elseif (getenv('REMOTE_ADDR')){
$ip = getenv('REMOTE_ADDR');
}else{
$ip = '';
}
return $ip;
}
*/
echo $ip = getIP();
function getIP() {if ($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif ($_SERVER['REMOTE_ADDR']){
$ip = $_SERVER['REMOTE_ADDR'];
}elseif (getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
}elseif (getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}elseif (getenv('REMOTE_ADDR')){
$ip = getenv('REMOTE_ADDR');
}else{
$ip = '';
}
return $ip;
}
以上就介绍了获取访问者的 客户端IP地址,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: 怎么处理分发卡号的问题
下一篇: 网页游戏的活动管理后台和管理后台