亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    thinkphp5怎么增加允許指定ip訪問模塊配置

    下面由thinkphp教程欄目給大家介紹thinkphp5增加允許指定ip訪問模塊配置方法,希望對需要的朋友有所幫助!

    thinkphp5怎么增加允許指定ip訪問模塊配置

    thinkphp5增加允許指定ip訪問模塊配置

    在config.php中添加

    'allow_module_ip' => ['admin' => '*'], // 設(shè)置某些ip可以訪問指定模塊

    ['admin' => '*'] 所有ip都可以訪問admin模塊,
    ['admin' => ['127.0.0.1','192.168.1.100']] 僅這兩個(gè)ip可以訪問admin模塊

    最好加在這個(gè)位置

    // 禁止訪問模塊 'deny_module_list'       => ['common'], // 設(shè)置某些ip可以訪問指定模塊 'allow_module_ip'        => ['admin' => '*'], // 默認(rèn)控制器名 'default_controller'     => 'Index',

    需要修改框架代碼
    thinkphp/library/think/App.php

    代碼位置如下

    public static function module($result, $config, $convert = null) {         if (is_string($result)) {             $result = explode('/', $result);         }         $request = Request::instance();         if ($config['app_multi_module']) {             // 多模塊部署             $module    = strip_tags(strtolower($result[0] ?: $config['default_module']));             $bind      = Route::getBind('module');             $available = false;             if ($bind) {                 // 綁定模塊                 list($bindModule) = explode('/', $bind);                 if (empty($result[0])) {                     $module    = $bindModule;                     $available = true;                 } elseif ($module == $bindModule) {                     $available = true;                 }             } elseif (!in_array($module, $config['deny_module_list']) && is_dir(APP_PATH . $module)) {                 $available = true;             }                          //region 設(shè)置了限制ip訪問模塊, 如:'allow_module_ip' => ['admin'=>['127.0.0.1']]             if (isset($config['allow_module_ip']) && isset($config['allow_module_ip'][$module])) {                 $allowIps = $config['allow_module_ip'][$module];                 if (!in_array($_SERVER['REMOTE_ADDR'], $allowIps) && $allowIps != '*') {                     $available = false;                 }              }             //end region              // 模塊初始化             if ($module && $available) {                 // 初始化模塊                 $request->module($module);                 $config = self::init($module);                 // 模塊請求緩存檢查                 $request->cache($config['request_cache'], $config['request_cache_expire'], $config['request_cache_except']);             } else {                 throw new HttpException(404, 'module not exists:' . $module);             }         } else {             // 單一模塊部署             $module = '';             $request->module($module);         }                  // ...... }

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)