//ip屏蔽 $userip = getRealIpAddr();//获取用户真实ip $ipreg='/((?:\d+\.){3})\d+/';//1个* //$ipreg2='~(\d+)\.(\d+)\.(\d+)\.(\d+)~'; //2个* $useripd = preg_replace($ipreg,"\\1*",$userip);//获取ip段 $shield = explode("\n",$ip);//屏蔽的ip转换为数组 foreach($shield as $val){ $shieldip[] = trim($val); } if (in_array($userip, $shieldip) || in_array($useripd, $shieldip)){ echo "ip已被禁用!";die; }
注:getRealIpAddr() 函数在https://www.weivb.com/article/36.html本篇文章中已有