php怎么设置后台某IP段可以登陆?

作者:袖梨 2022-06-24

 

 代码如下 复制代码
public function login() {
        //设定IP段登录
        if(getenv("HTTP_CLIENT_IP")) {
            $onlineip = getenv('HTTP_CLIENT_IP');
                 }
                 elseif(getenv('HTTP_X_FORWARDED_FOR')){
                         $onlineip = getenv('HTTP_X_FORWARDED_FOR');
                 }
                 elseif(getenv('REMOTE_ADDR')){
                         $onlineip = getenv('REMOTE_ADDR');
                 }
                 else{
                         $onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
                 }
//                 echo $onlineip;
                 $adminip = $onlineip;
                 $arrayip = array('117.121.48.*','127.0.0.*');//ip段
                 $ipregexp = implode('|', str_replace( array('*','.'), array('d+','.') ,$arrayip) );
                 $allow = preg_match("/^(".$ipregexp.")$/", $adminip);
       
                 if ($allow != 1) {
                         showmessage(L('你的ip地址不在被允许的范围内!'),'?m=admin&c=index&a=login',6000);
                 }

把下面代码放到你的网站后台登录入口调用,然后再把m=admin&c=index&a=login改成你的地址就可以了。

相关文章

精彩推荐