thinkphp5配置指定ip存取模組
在config.php中加入
'allow_module_ip' => ['admin' => '*'], // 設定某些ip可以訪問指定模組
['admin' => '*'] 所有ip都可以存取admin模組,
['admin' => ['127.0.0.1','192.168.1.100'] ] 只有這兩個ip可以存取admin模組
最好加在這個位置
// 禁止访问模块 'deny_module_list' => ['common'], // 设置某些ip可以访问指定模块 'allow_module_ip' => ['admin' => '*'], // 默认控制器名 '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 设置了限制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); } // ...... }
推薦教學:《TP5》
以上是thinkphp5配置指定ip存取模組的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

寶塔部署thinkphp5報錯的解決方法:1、開啟寶塔伺服器,安裝php pathinfo擴充並啟用;2、設定「.access」文件,內容為「RewriteRule ^(.*)$ index.php?s=/$1 [QSA ,PT,L]」;3、在網站管理裡面,啟用thinkphp的偽靜態即可。

thinkphp5 url重寫不行的解決方法:1、查看httpd.conf設定檔中是否載入了mod_rewrite.so模組;2、將AllowOverride None中的None改為All;3、修改Apache設定檔.htaccess為「RewriteRule ^ (.*)$ index.php [L,E=PATH_INFO:$1]」保存即可。

thinkphp5取得請求網址的方法:1.使用「\think\Request」類別的「$request = Request::instance();」方法取得目前的url資訊;2、透過自帶的助手函數「$request-> url()」取得包含網域的完整URL位址。

移除thinkphp5標題列icon的方法:1、找到thinkphp5框架public下的favicon.ico檔案;2、刪除該檔案或選擇另一張圖片命名改為favicon.ico,並取代原favicon.ico檔案即可。

thinkphp5 post無法得到值是因為TP5是透過strpos函數在Header的content-type值中找出app/json字串的,其解決辦法就是設定Header的content-type值為app/json即可。

thinkphp5提示控制器不存在的解決方法:1、檢查對應的控制器裡面的命名空間是否寫對,修改為正確的命名空間;2、打開對應的tp文件,修改類別名稱即可。

ThinkPHP5查詢昨天資料的方法:1、開啟ThinkPHP5相關檔案;2、透過表達式「db('table')->whereTime('c_time', 'yesterday')->select();」查詢昨天的資料即可。

thinkphp5設定報錯提示的方法:1、進入專案根目錄下的public資料夾,開啟index.php入口檔案;2、檢視偵錯模式開關的註解;3、將「APP_DEBUG」常數的值調整為true即可展示錯誤訊息提示。
