本文整理匯總了PHP中IP::ClientIP方法的典型用法代碼示例。如果您正苦於以下問題:PHP IP::ClientIP方法的具體用法?PHP IP::ClientIP怎麽用?PHP IP::ClientIP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IP
的用法示例。
在下文中一共展示了IP::ClientIP方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getClientIP
/**
* Get IP
*
* @access public
* @return string
*/
public static function getClientIP()
{
if (self::$ClientIP !== FALSE) {
return self::$ClientIP;
}
$CieIP = (isset($_SERVER['HTTP_CLIENT_IP']) and $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
$RemIP = (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
$ForIP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
if ($CieIP && $RemIP) {
self::$ClientIP = $CieIP;
} elseif ($RemIP) {
self::$ClientIP = $RemIP;
} elseif ($CieIP) {
self::$ClientIP = $CieIP;
} elseif ($ForIP) {
self::$ClientIP = $ForIP;
}
if (strstr(self::$ClientIP, ',')) {
$x = explode(',', self::$ClientIP);
self::$ClientIP = end($x);
}
// checked IP address
$CheckIP = new IPValidator();
if (!$CheckIP->isValid(self::$ClientIP)) {
self::$ClientIP = '0.0.0.0';
}
unset($CheckIP);
unset($CieIP);
unset($RemIP);
unset($ForIP);
return self::$ClientIP;
}