Weather App Project
Weather App Project
HTML (index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Weather App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Weather App</h1>
<form method="post">
<input type="text" name="city" placeholder="Enter city name" required>
<button type="submit">Get Weather</button>
</form>
<?php include 'weather.php'; ?>
</div>
</body>
</html>
CSS (style.css):
body {
font-family: Arial, sans-serif;
background: linear-gradient(to top right, #00aaff, #00ffaa);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: white;
padding: 20px 30px;
border-radius: 15px;
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
text-align: center;
}
input, button {
padding: 10px;
margin: 10px;
font-size: 16px;
}
PHP (weather.php):
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$city = htmlspecialchars($_POST['city']);
$apiKey = "YOUR_API_KEY_HERE";
$apiUrl =
"https://api.openweathermap.org/data/2.5/weather?q={$city}&appid={$apiKey}&units=metric"
;
$weather_data = file_get_contents($apiUrl);
$weather = json_decode($weather_data);