欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php获取客户端ip,简单实用

程序员文章站 2022-05-20 17:17:29
...
php获取客户端ip,简单实用

function getOnlineIP() {
$cip = getenv ( 'HTTP_CLIENT_IP' );
$xip = getenv ( 'HTTP_X_FORWARDED_FOR' );
$rip = getenv ( 'REMOTE_ADDR' );
$srip = $_SERVER ['REMOTE_ADDR'];

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;
}
// 烈6715网(LieHuo28.Net)教09
preg_match ( "/[\d\.]{7,15}/", $onlineip, $match );
$onlineip = $match [0] ? $match [0] : 'unknown';

return $onlineip;
}

本文地址:http://www.52blogger.com/archives/597