/**
* @author chenliujin <[email protected]>
* @since 2014-04-17
*/
function get_client_ip()
{
$checks = array(
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
'HTTP_X_COMING_FROM',
'HTTP_COMING_FROM',
'HTTP_CLIENT_IP',
'X-Real-IP',
'HTTP_X_REAL_IP',
);
foreach ($checks as $check) {
if (isset($_SERVER[$check])) {
$ip = $_SERVER[$check];
if (($pos = strpos($ip, ',')) != FALSE) {
$ip = substr($ip, 0, $pos);
}
$ipnum = ip2long($ip);
if ($ipnum !== -1 && $ipnum !== FALSE && long2ip($ipnum) === $ip) {
if (($ipnum < 167772160 || $ipnum > 184549375) && ($ipnum < - 1408237568 || $ipnum > - 1407188993) && ($ipnum < - 1062731776 || $ipnum > - 1062666241))
return $ip;
}
}
}
return $_SERVER['REMOTE_ADDR'];
}
1.HTTP_X_REAL_IP or HTTP_X_FORWARDED_FOR?
http://gtranslate.net/forum/http-real-http-forwarded-for-t2980.html
2. http://www.cnblogs.com/lmule/archive/2010/10/15/1852020.html