简体   繁体   English

php速率限制不适用于curl请求

[英]Php rate limit doesn't work with curl requests

I took this function to limit http requests surfing on internet: 我使用此功能来限制在互联网上浏览的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");

It works with browser 与浏览器一起使用

与浏览器

but if I try a request with curl: 但是如果我尝试使用curl的请求:

curl http://localhost/project/p.php

卷曲 Nothing happens 什么都没发生

How can I update this in order to make rate limit valid for curl too? 我如何更新此设置以使速率限制也适用于卷曲?

SOLUTION

I check if cookies are accepted by the client, if no exit: 我检查客户端是否接受cookie,如果没有退出:

setcookie('test', 1, time()+3600);
if(count($_COOKIE) == 0){
     die ("Cookie Not Enabled");
}

to make a curl request with cookies a save a cookie file and then I make another request with cookies: 用cookie发出卷曲请求,保存一个cookie文件,然后用cookie发出另一个请求:

curl http://localhost/project/p.php -c cookie-jar.txt

curl http://localhost/project/register.php --cookie "PHPSESSID=g90tqc0hvp6sodods9jisss912"

SOLUTION

I check if cookies are accepted by the client, if no exit: 我检查客户端是否接受cookie,如果没有退出:

setcookie('test', 1, time()+3600);
if(count($_COOKIE) == 0){
     die ("Cookie Not Enabled");
}

to make a curl request with cookies a save a cookie file and then I make another request with cookies: 用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM