在phpcms中可以限制某些ip段或者某些具体的ip登录,具体的方法如下:
if($_SERVER['HTTP_CDN_SRC_IP']){
$onlineip=$_SERVER['HTTP_CDN_SRC_IP'];
}
elseif($_SERVER['HTTP_CLIENT_IP']){
$onlineip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif($_SERVER['HTTP_X_FORWARDED_FOR']){
$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
elseif($_SERVER['REMOTE_ADDR']){
$onlineip=$_SERVER['REMOTE_ADDR'];
}
else{
$onlineip=$_SERVER['REMOTE_ADDR'];
}
//echo $onlineip;
$adminip=$onlineip;
$arrayip= array('192.168.0.*','127.0.0.*','192.168.50.*');//ip段,只有这几个ip段的可以访问
$exitip= array('*.*.*.*','*.*.*.*');//出口ip,这个是具体的ip,*所占得位置需要填上ip
$ipregexp=implode('|',str_replace(array('*','.'),array('\d+','\.') ,$arrayip) );
$allow=preg_match("/^(".$ipregexp.")$/", $adminip);
if($allow!=1) {
if(!in_array($adminip,$exitip))die('呔,你个坏人!');
}