36 lines
864 B
PHP
Executable File
36 lines
864 B
PHP
Executable File
<?php
|
||
|
||
namespace app\common\behavior;
|
||
|
||
use think\Request;
|
||
use think\Config;
|
||
|
||
load_trait('controller/Jump');
|
||
|
||
/**
|
||
* Description of CheckIp
|
||
* 检测用户访问的ip
|
||
*/
|
||
class CheckIp {
|
||
|
||
use \traits\controller\Jump;
|
||
|
||
/**
|
||
* 检测用户IP
|
||
*/
|
||
public function run() {
|
||
$deny_ip = Config::get('admin_deny_ip');
|
||
$allow_ip = Config::get('admin_allow_ip');
|
||
$ip = Request::instance()->ip();
|
||
//$this->error('禁止访问');
|
||
if (!is_administrator() && $deny_ip) {
|
||
in_array($ip, explode(',', $deny_ip)) && $this->error('禁止访问'); // 检查IP地址访问
|
||
}
|
||
if (!is_administrator() && $allow_ip) {
|
||
!in_array($ip, explode(',', $allow_ip)) && $this->error('禁止访问'); // 检查IP地址访问
|
||
}
|
||
\think\Log::record("[ 访问者IP ]:" . $ip);
|
||
}
|
||
|
||
}
|