//检查白名单ip
private function _checkAllowIp()
{
$allowIp = ['203.195.156.12'];
$ip = $this->getIp();
if (!in_array($ip, $allowIp)) {
exit();
}
}
/**
* 获取客户端访问ip
*/
private function getIp()
{
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} else if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} else if (getenv('REMOTE_ADDR')) {
$ip = getenv('REMOTE_ADDR');
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$ips = explode(',', $ip);
if (count($ips) > 1) {
$ip = $ips[0];
}
return $ip;
}