I took this function to limit http requests surfing on internet:
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 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:
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:
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:
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:
curl http://localhost/project/p.php -c cookie-jar.txt
curl http://localhost/project/register.php --cookie "PHPSESSID=g90tqc0hvp6sodods9jisss912"