6. ip黑名单

CheckIp.php代码:文件位置app\middleware\CheckIp.php

 

https://www.cnblogs.com/wesky/p/12661175.html

 

 

复制代码
<?php
namespace app\middleware;

class CheckIp
{
    // 状态 关闭:false,开启:true
    private $status = true;
    // ip库
    private $StoreIp = ['127.0.0.2','127.0.0.1'];

    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        // 禁止访问
        if($this->status==true){
            if(in_array($request->ip(),$this->StoreIp)){
                exit('禁止访问');
            }
        }
        return $next($request);
    }


}
 
posted @ 2022-05-15 09:56  棉花糖88  阅读(34)  评论(0)    收藏  举报