<?php /*如果是本地服务器获取客户端的ip地址是 127.0.0.1 如果是域名服务器获取客户端的是公网ip地址*/ function get_client_ip() { $ipaddress = ‘‘; if (getenv(‘HTTP_CLIENT_IP‘)) $ipaddress = getenv(‘HTTP_CLIENT_IP‘); else if(getenv(‘HTTP_X_FORWARDED_FOR‘)) $ipaddress = getenv(‘HTTP_X_FORWARDED_FOR‘); else if(getenv(‘HTTP_X_FORWARDED‘)) $ipaddress = getenv(‘HTTP_X_FORWARDED‘); else if(getenv(‘HTTP_FORWARDED_FOR‘)) $ipaddress = getenv(‘HTTP_FORWARDED_FOR‘); else if(getenv(‘HTTP_FORWARDED‘)) $ipaddress = getenv(‘HTTP_FORWARDED‘); else if(getenv(‘REMOTE_ADDR‘)) $ipaddress = getenv(‘REMOTE_ADDR‘); else $ipaddress = ‘UNKNOWN‘; return $ipaddress; } echo get_client_ip(); ?>
原文地址:https://www.cnblogs.com/itfat/p/10928517.html
时间: 2024-11-14 13:08:15