首頁  >  文章  >  後端開發  >  php获取客户端ip,简单实用_PHP教程

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

WBOY
WBOY原創
2016-07-21 14:53:54965瀏覽

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/364682.htmlTechArticlephp获取客户端ip,简单实用 function getOnlineIP() { $cip = getenv ( 'HTTP_CLIENT_IP' ); $xip = getenv ( 'HTTP_X_FORWARDED_FOR' ); $rip = getenv ( 'REMOTE_ADDR' ); $srip = $_...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn