[英]Php rate limit doesn't work with curl requests
我使用此功能来限制在互联网上浏览的http请求:
session_start();
if (isset($_SESSION['LAST_CALL'])) {
$last = strtotime($_SESSION['LAST_CALL']);
$curr = strtotime(date("Y-m-d h:i:s"));
$sec = abs($last - $curr);
if ($sec <= 2) {
die('Rate Limit Exceeded'); // rate limit
}
}
$_SESSION['LAST_CALL'] = date("Y-m-d h:i:s");
与浏览器一起使用
但是如果我尝试使用curl的请求:
curl http://localhost/project/p.php
什么都没发生
我如何更新此设置以使速率限制也适用于卷曲?
解
我检查客户端是否接受cookie,如果没有退出:
setcookie('test', 1, time()+3600);
if(count($_COOKIE) == 0){
die ("Cookie Not Enabled");
}
用cookie发出卷曲请求,保存一个cookie文件,然后用cookie发出另一个请求:
curl http://localhost/project/p.php -c cookie-jar.txt
curl http://localhost/project/register.php --cookie "PHPSESSID=g90tqc0hvp6sodods9jisss912"
解
我检查客户端是否接受cookie,如果没有退出:
setcookie('test', 1, time()+3600);
if(count($_COOKIE) == 0){
die ("Cookie Not Enabled");
}
用cookie发出卷曲请求,保存一个cookie文件,然后用cookie发出另一个请求:
curl http://localhost/project/p.php -c cookie-jar.txt
curl http://localhost/project/register.php --cookie "PHPSESSID=g90tqc0hvp6sodods9jisss912"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.