-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
103 lines (78 loc) · 3.71 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!-- /*
* @Author Kumar Vibhanshu <vibhanshumonty@gmail.com>
* @Package Get Weather Details
* @weather_Api Integration
* visit: https://kmrvibhanshu.000webhostapp.com/weather/
*/ -->
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$city = $_POST['city'];
$get = json_decode(file_get_contents('http://ip-api.com/json/'), true);
date_default_timezone_set($get['timezone']);
$string = "http://api.openweathermap.org/data/2.5/weather?q=" . $city . "&units=metric&appid=27c9193ebc037c4ee9acd2c3c1d2816f";
$data_fetch = json_decode(file_get_contents($string), true);
$temp = $data_fetch['main']['temp'];
$icon = $data_fetch['weather'][0]['icon'];
$visibility = $data_fetch['visibility'];
$visibilitykm = $visibility / 1000;
$country = "<h1 class='w3-xxxlarge w3-animate-zoom'><b>" . $data_fetch['name'] . "," . $data_fetch['sys']['country'] . "</h1></b>";
$logo = "<center><img src='http://openweathermap.org/img/w/" . $icon . ".png'></center>";
$desc = "<b><p>" . $data_fetch['weather'][0]['description'] . "</p></b>";
$temperature = "<b>Temp:" . $temp . "°C</b><br>";
$clouds = "<b>Clouds:" . $data_fetch['clouds']['all'] . "%</b><br>";
$humidity = "<b>Humidity:" . $data_fetch['main']['humidity'] . "%</b><br>";
$windspeed = "<b>Wind Speed:" . $data_fetch['wind']['speed'] . "m/s</b><br>";
$pressure = "<b>Pressure:" . $data_fetch['main']['pressure'] . "hpa</b><br>";
$visibility = "<b>Visibility:" . $visibilitykm . "Km</b><br>";
$sunrise = "<b>Sunrise:" . date('h:i A', $data_fetch['sys']['sunrise']) . "</b><br>";
$sunset = "<b>Sunset:" . date('h:i A', $data_fetch['sys']['sunset']) . "</b>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Weather - K. Vibhanshu</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<center>
<h2>Get Weather Details</h2>
<div class="card text-center w-100">
<div class="card-header">Weather Info</div>
<div class="card-body">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="api_form">
<div class="email-login" style="background-color:#ffffff;">
<div class="form-group">
<input type="text" name="city" class=" form-control" required="" placeholder="Enter City Name">
</div>
</div>
<div class="submit-row" style="margin-bottom:8px;padding-top:0px;">
<input type="submit" name="submit" value="Get Weather" class="btn btn-primary btn-block box-shadow" />
</div>
</form>
<div class="">
<?php if (empty($temperature)) {
} else {
echo $city."<br/>";
echo $temperature;
echo $clouds;
echo $humidity;
echo $windspeed;
echo $pressure;
echo $visibility;
}
?>
</div>
</div>
<div class="card-footer"> <a href="https://github.com/vibhanshumonty" target="_blank">K. Vibhanshu</a></div>
</div>
</center>
</div>
</body>
</html>