💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
CheckIp.php代码:文件位置app\\middleware\\CheckIp.php [![复制代码](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "复制代码") ~~~ <?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); } } ~~~ [![复制代码](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "复制代码") 加载中间件:app/index/middleware.php [![复制代码](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "复制代码") ~~~ <?php // 这是系统自动生成的middleware定义文件 return [ 'think\middleware\LoadLangPack', // 加载中间件 app\middleware\CheckIp::class ]; ~~~