Rate limit of openweathermap.org API Call

This commit is contained in:
Divlo
2019-10-08 12:44:03 +02:00
parent f387cb179d
commit d90bc65c61
2 changed files with 14 additions and 1 deletions

View File

@ -1,4 +1,17 @@
<?php
// Rate limit of 1 request per 2 second
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) {
$data = 'Rate Limit Exceeded';
echo $data;
}
}
$_SESSION['LAST_CALL'] = date("Y-m-d h:i:s");
include 'keyVariable.php';
ini_set("allow_url_fopen", 1);
$cityName = $_COOKIE['city'];