在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段懂诗,只有這幾個(gè)ip段的可以訪問(wèn)
$exitip= array('*.*.*.*','*.*.*.*');//出口ip抽活,這個(gè)是具體的ip,*所占得位置需要填上ip
$ipregexp=implode('|',str_replace(array('*','.'),array('\d+','\.') ,$arrayip) );
$allow=preg_match("/^(".$ipregexp.")$/", $adminip);
if($allow!=1) {
if(!in_array($adminip,$exitip))die('呔孙技,你個(gè)壞人棠枉!');
}