您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何获取用户的ip地址

2024/4/14 14:34:46发布18次查看
ip地址: internet协议地址(ip地址)是分配给连接到使用internet协议进行通信的计算机网络的每个设备的数字标签。ip地址有两个主要功能:主机或网络接口标识和位置寻址。
$_server['remote_addr']:浏览当前页面的用户计算机的ip地址
$_server['http_client_ip']:客户端的ip(推荐学习:php编程从入门到精通)
$_server['http_x_forwarded_for']:浏览当前页面的用户计算机的网关
$_server['http_x_real_ip']:nginx 代理模式下,获取客户端真实ip
/** * 获取客户端ip地址 */function real_ip(){ $ip = $_server['remote_addr']; if (isset($_server['http_x_forwarded_for']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_server['http_x_forwarded_for'], $matches)) { foreach ($matches[0] as $xip) { if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) { $ip = $xip; break; } } } elseif (isset($_server['http_client_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_client_ip'])) { $ip = $_server['http_client_ip']; } elseif (isset($_server['http_cf_connecting_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_cf_connecting_ip'])) { $ip = $_server['http_cf_connecting_ip']; } elseif (isset($_server['http_x_real_ip']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_server['http_x_real_ip'])) { $ip = $_server['http_x_real_ip']; } return $ip;}
以上就是php如何获取用户的ip地址的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product