diff --git a/php/04_owmapi/actions.php b/php/04_owmapi/actions.php new file mode 100644 index 0000000..d006336 --- /dev/null +++ b/php/04_owmapi/actions.php @@ -0,0 +1,51 @@ + $mesto, + "units" => "metric", + "lang" => "cz", + "appid" => $API_KEY +]); +//echo $url; +// file_get_contents stáhne obsah URL jako string +// @ potlačí varování (při chybě vrátí false) +$odpoved = @file_get_contents($url); +if ($odpoved === false) { + $_SESSION["chyba"] = "Nepodařilo se s pojit s API. Zkontrolujte název města"; + $_SESSION["mesto"] = $mesto; + header("Location: index.php"); + exit; +} +//echo $odpoved; +$data = json_decode($odpoved,true); +//echo $data; + +// kontrola chybového kodu +if (isset($data["cod"]) && $data["cod"] != 200){ + $_SESSION["chyba"] = "Město '$mesto' nebylo nalezeno"; + $_SESSION["mesto"] = $mesto; + header("Location: index.php"); + exit; +} +// ÚSPĚCH +$_SESSION["pocasi"] = $data; +header("Location: vysledek.php"); +exit; +?> \ No newline at end of file diff --git a/php/04_owmapi/index.php b/php/04_owmapi/index.php new file mode 100644 index 0000000..30e0bd4 --- /dev/null +++ b/php/04_owmapi/index.php @@ -0,0 +1,34 @@ + + + + + + + Document + + +

OpenWeatherMap

+
+ + +
+ + +
+ + + \ No newline at end of file diff --git a/php/04_owmapi/init.php b/php/04_owmapi/init.php new file mode 100644 index 0000000..86ee131 --- /dev/null +++ b/php/04_owmapi/init.php @@ -0,0 +1,6 @@ + extension=openssl +$API_KEY = "cdcbb82b14e8e3e85117686c68e19a5b"; +$URL_BASE = "https://api.openweathermap.org/data/2.5/weather" + +?> \ No newline at end of file diff --git a/php/04_owmapi/vysledek.php b/php/04_owmapi/vysledek.php new file mode 100644 index 0000000..6897cd9 --- /dev/null +++ b/php/04_owmapi/vysledek.php @@ -0,0 +1,57 @@ + + + + + + + Počasí - <?php echo(htmlspecialchars($pocasi["name"]));?> + + +

Počasí

+

+ - + +

+
+ +
+
+ Teplota - °C +
+
+ Pocitová - °C +
+
+ Vlhkost - % +
+
+ Vítr - km/h +
+
+ Tlak - hPa +
+
+ Východ slunce - +
+
+ Západ slunce - +
+ +
+ + + \ No newline at end of file