weather/index.php

35 lines
802 B
PHP
Raw Permalink Normal View History

2022-11-04 23:43:25 +07:00
<?php
header('Content-Type: application/json; charset=utf-8');
$q = $_REQUEST["q"];
$key = "API_KEY";
if($q == ""){
$myfile = fopen("cache.txt", "r") or die("Unable to open file!");
$teks = fread($myfile,filesize("cache.txt"));
fclose($myfile);
$pieces = explode("=", $teks);
$marks = array("suhu"=>$pieces[0], "kelembapan"=>$pieces[1], "presipitasi"=>$pieces[2], "angin"=>$pieces[3],"cuaca"=>$pieces[4], "last_update"=>$pieces[5], "server_update"=>$pieces[6]);
echo json_encode($marks, JSON_PRETTY_PRINT);
}
else {
$txt = base64_decode($q);
$pieces = explode("=", $txt);
if(strcmp($pieces[7], $key) == 0) {
$myfile = fopen("cache.txt", "w") or die("Unable to open file!");
fwrite($myfile, $txt);
fclose($myfile);
echo "Done!";
}
else {
echo "Key Invalid";
fclose($myfile);
}
}
?>