Add in config.php
'allow_module_ip' => ['admin' => '*'], // Set some IP can access the specified module
['admin' => '*'] All IPs can access the admin module,
['admin' => ['127.0.0.1', '192.168.1.100']] Only these two IPs can access the admin module
It is best to add it in this location
// 禁止访问模块 'deny_module_list' => ['common'], // 设置某些ip可以访问指定模块 'allow_module_ip' => ['admin' => '*'], // 默认控制器名 'default_controller' => 'Index',
Need to modify the framework code
thinkphp/ library/think/App.php
The code is as follows
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); } // ...... }
Recommended tutorial: "TP5"
The above is the detailed content of thinkphp5 adds a method to allow specified IP to access the module. For more information, please follow other related articles on the PHP Chinese website!

宝塔部署thinkphp5报错的解决办法:1、打开宝塔服务器,安装php pathinfo扩展并启用;2、配置“.access”文件,内容为“RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]”;3、在网站管理里面,启用thinkphp的伪静态即可。

thinkphp5 post得不到值是因为TP5是通过strpos函数在Header的content-type值中查找app/json字符串的,其解决办法就是设置Header的content-type值为app/json即可。

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提示控制器不存在的解决办法:1、检查对应的控制器里面的命名空间是否写对,修改为正确的命名空间;2、打开相应的tp文件,修改类名即可。

thinkphp5设置报错提示的方法:1、进入项目根目录下的public文件夹,打开index.php入口文件;2、查看调试模式开关的注释;3、将“APP_DEBUG”常量的值调整为true即可展示错误信息提示。

ThinkPHP5查询昨天数据的方法:1、打开ThinkPHP5相关文件;2、通过表达式“db('table')->whereTime('c_time', 'yesterday')->select();”查询昨天的数据即可。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
