Rumah > Artikel > pembangunan bahagian belakang > PHP获取用户IP地址
PHP获取用户IP地址
<?php function getClientIp() { $uip = ''; if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknow')) { $uip = $_SERVER['HTTP_X_FORWARDED_FOR']; strpos($uip, ',') && list($uip) = explode(',', $uip); } elseif(!empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknow')) { $uip = $_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknow')) { $uip = $_SERVER['REMOTE_ADDR']; } return $uip; } echo getClientIp();
以上就介绍了PHP获取用户IP地址,包括了方面的内容,更多相关内容请关注PHP中文网(www.php.cn)!