php获取客户端ip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php $onlineip = ""; $cip = getenv('HTTP_CLIENT_IP'); $xip = getenv('HTTP_X_FORWARDED_FOR'); $rip = getenv('REMOTE_ADDR'); $srip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown'; if($cip && strcasecmp($cip, 'unknown')) { $onlineip = $cip; } elseif($xip && strcasecmp($xip, 'unknown')) { $onlineip = $xip; } elseif($rip && strcasecmp($rip, 'unknown')) { $onlineip = $rip; } elseif($srip && strcasecmp($srip, 'unknown')) { $onlineip = $srip; } if(preg_match("/[d.]{7,15}/", $onlineip, $match)) { $onlineip = $match[0]; } else { $onlineip = 'unknown'; } echo $onlineip; ?> |
分类: 技术