本文整理汇总了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;
}