PHP获取客户端IP地址

2.4k 记录 发表评论
先上代码,再解析: /** * 获取客户端IP */ function getClientIp() { $ip = 'unknown'; $unknown = 'unknown'; if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)) { // 使用透明代理、欺骗性代理的情况 $ip = $_SERVER['…