Home  >  Article  >  Backend Development  >  Get the client IP with php, simple and practical_PHP tutorial

Get the client IP with php, simple and practical_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:53:54934browse

Get the client IP with php, simple and practical

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

return $onlineip;
}

This article address: http:// /www.52blogger.com/archives/597

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364682.htmlTechArticlephp gets the client ip, simple and practical function getOnlineIP() { $cip = getenv ( 'HTTP_CLIENT_IP' ); $ xip = getenv ( 'HTTP_X_FORWARDED_FOR' ); $rip = getenv ( 'REMOTE_ADDR' ); $srip = $_...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn