This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/php/getWeatherJson.php

21 lines
663 B
PHP
Raw Normal View History

<?php
// Rate limit of 1 request per 2 second
session_start();
if (isset($_SESSION['LAST_CALL'])) {
2019-11-08 21:17:50 +01:00
$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'];
$url = 'https://api.openweathermap.org/data/2.5/weather?q='.$cityName.'&lang=fr&units=metric&appid='.$apiWeather;
$json = file_get_contents($url);
// $obj = json_decode($json);
echo $json;