allowedIPs(); // 校验用户IP是否在允许的范围内 $isValidIP = false; if(in_array(self::ALL,$allowedIPs)) { $isValidIP = true; }else{ foreach ($allowedIPs as $allowedIP) { if (strpos($allowedIP, '/') !== false) { // IP段表示法校验 list($subnet, $mask) = explode('/', $allowedIP); if ((ip2long($userIP) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) { $isValidIP = true; break; } } else { // 单个IP地址校验 if ($allowedIP === $userIP) { $isValidIP = true; break; } } } } return $isValidIP; } public function allowedIPs(){ $allowedIPs = Settings::where('name','allowedIPs')->first(); if(empty($allowedIPs) || empty($allowedIPs->value)) return [self::ALL]; return explode(',',$allowedIPs->value); } //设置登录错误次数(超过三次) public static function errorSetLogin($cacheKey){ if(Cache::has($cacheKey)){ $num = Cache::get($cacheKey); $num++; Cache::put($cacheKey,$num,30); if($num >= 3){ return ['账号密码输入错误3次,30分钟内限制登录!']; }else{ return ['账号密码输入错误第'. $num .'次!']; } }else{ Cache::add($cacheKey,1,30); return ['密码输入错误!']; } } //判断是否限制登录 public static function isLoginlimitation($cacheKey){ if(Cache::has($cacheKey)){ $num = Cache::get($cacheKey); if($num >= 3) return true; } return false; } }