当前位置:网站首页>TP5 restrict access frequency
TP5 restrict access frequency
2022-06-27 18:23:00 【When you're lonely, the dog stays with you】
effect

1. Turn on Redis

Open your Redis Software If not, it can be in Small skin Environmental Science Installed in software management

2 .tp5 To configure config.php

'cache' => [
// Driving mode
'type' => 'redis',
// Cache used by default
'default' => [
// Driving mode
'type' => 'redis',
// Cache save Directory
'path' => CACHE_PATH,
],
// Cache prefix
'prefix' => '',
// Cache lifetime 0 Indicates permanent cache
'expire' => 0,
// redis cache
'redis' => [
// Driving mode
'type' => 'redis',
// Server address
'host' => '127.0.0.1',
],
],3.php Code
function requestAccess($time=1,$limit=3){
// Get access to the user's IP
$ip=md5(request()->ip());
// Get the access interface path
$path=request()->path();
// take IP And the access interface path md5 Encrypted into a string , This represents the interface accessed by the same customer .
$UV=md5($ip.$path);
// Every IP And the number of times the interface cannot exceed per minute
$cacheIp=Cache::get($UV)?:0;
if($cacheIp){
if($cacheIp>$limit){
return false;
}else{
Cache::inc($UV,1);
}
}else{
Cache::set($UV,1,60);
}
// For each request IP Address 、 Parameters and paths are spliced into an identical interface of the same user .
$post=json_encode(request()->post());
$name=md5($path.$post);
// How long can each same data not be requested
$cache=Cache::get($name);
if($cache==$ip){
return false;
}else{
Cache::set($name,$ip,$time);
return true;
}
}4. call
When you need to limit the frequency of interface calls
if (!$this->requestAccess()){
echo json(['code'=>200,'msg'=>' Interface calls are too frequent '])->send();die;
}边栏推荐
- Hash encryption
- Advanced learning of MySQL -- Application -- view, stored procedure, trigger
- The power of code refactoring: how to measure the success of refactoring
- Jeesite 4.0 replaces the default view style and customizes the theme
- [UVM foundation] UVM_ Is in agent_ Active variable definition
- 建立自己的网站(10)
- Autodesk Navisworks 2022软件安装包下载及安装教程
- 07. Express routing
- Handling method of occasional error reporting on overseas equipment
- Adaoracle supports multi chain distributed Oracle with wide area node quotation
猜你喜欢

Anfulai embedded weekly report (issue 252): February 7, 2022 to February 13, 2022

Sliding window + monotone queue concept and example (p1886 Logu)

d3dx9_ How to repair 25.dll? d3dx9_ 25.dll where to download
![[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes](/img/cb/0be2b2cf3b2cfa903190b7795d3cd7.jpg)
[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes
![[UVM basics] set a monitor at the input port of the DUT to explain the necessity](/img/72/0cecd17ab2c893b978b0995363cfcf.jpg)
[UVM basics] set a monitor at the input port of the DUT to explain the necessity

Overview of Inspur Yunxi database executor

Autodesk Navisworks 2022软件安装包下载及安装教程

全面解析零知识证明:消解扩容难题 重新定义「隐私安全」

leetcode 19. Delete the penultimate node of the linked list

Shardingsphere sharding proxy actual combat scenario
随机推荐
The European unified charging specification act was passed before the end of the year, and it is planned to expand to products such as laptop and keyboard
Openssf security plan: SBOM will drive software supply chain security
(5) SPI application design and simulation verification 3 - verification code implementation
leetcode 19. Delete the penultimate node of the linked list
写在eclipse里面,与数据库连接查询之后的问题
Anfulai embedded weekly report (issue 252): February 7, 2022 to February 13, 2022
Advanced learning of MySQL -- Application -- view, stored procedure, trigger
Determine the maximum number of specific words in a string
当发布/订阅模式遇上.NET
Unity 阴影——阴影平坠(Shadow pancaking)
How to improve it electronic equipment performance management
d3dx9_ Where is 35.dll? d3dx9_ Where can I download 35.dll
09 route guard authenticates URL
Application practice of day13 for loop distinguish the application of traversing break continue
SQLite net (SQLite is used by unity, WPF and WinForm)
[UVM foundation] UVM_ Is in agent_ Active variable definition
Study on heritability and field experiment design
[UVM foundation] can only be used in build_ Research on executing instantiation action in phase
ROS "topic" programming implementation
黑马程序员-软件测试基础班-02-30-45工具代开浏览器运行代码,音、视频、测试点,音视频标签,布局标签。超链接语法进阶,绝对路径,相对路径