当前位置:网站首页>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;
}边栏推荐
- Oracle concept II
- Oracle的NUMBER长度超过19之后,实体使用Long映射,导致出现问题是为什么?
- [UVM foundation] UVM_ Is in agent_ Active variable definition
- 广汽三菱全新欧蓝德首次国内亮相于年内上市 产品力全面焕新
- d3dx9_ How to repair 25.dll? d3dx9_ 25.dll where to download
- Generate zip package command
- 【多线程】线程通信调度、等待集 wait() 、notify()
- Halcon: discrete digital OCR recognition
- Why should string be designed to be immutable?
- 10 minutes to master the installation steps of MySQL
猜你喜欢

Bit. Store: long bear market, stable stacking products may become the main theme

Teach you how to realize pynq-z2 bar code recognition

Oracle concept II

Shardingsphere sharding proxy actual combat scenario

Advanced learning of MySQL -- Application -- Optimization of other SQL statements

Why should string be designed to be immutable?

Wanzhou gold industry: what are the differences between gold t+d investment and other investments?

Detailed explanation of various GPIO input and output modes (push-pull, open drain, quasi bidirectional port)

Determine the maximum number of specific words in a string

Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
随机推荐
Use pyinstaller to package py files into exe. Precautions and error typeerror:_ get_ sysconfigdata_ name() missing 1...‘ check_ Solutions to exists'
写在eclipse里面,与数据库连接查询之后的问题
d3dx9_ How to repair 40.dll? Win10 system d3dx9_ What if 40.dll is lost?
Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration
Drawing for example study of flashcc
wheel ui
When the publish / subscribe mode encounters NET
DOM object in JS
模拟进程调度
About binary
D use in
Explain the distributed computing of Apache skywalking OAP in detail
Oracle concept II
leetcode 200. Number of islands
Adaoracle supports multi chain distributed Oracle with wide area node quotation
Oracle TRUNC function processing date format
广汽三菱全新欧蓝德首次国内亮相于年内上市 产品力全面焕新
[leetcode] 2. Add two numbers (user-defined listnode), medium
Control file related views
CDH cluster installation