29 lines
828 B
PHP
29 lines
828 B
PHP
<?php
|
|
session_start();
|
|
require_once 'db.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = trim($_POST['email']);
|
|
$password = $_POST['password'];
|
|
|
|
$conn = getConnection();
|
|
$stmt = $conn->prepare("SELECT id, username, password FROM Users WHERE email = ?");
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
header('Location: home.php');
|
|
exit;
|
|
} else {
|
|
echo "Invalid credentials.";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<form method="POST">
|
|
<input type="email" name="email" placeholder="Email" required>
|
|
<input type="password" name="password" placeholder="Password" required>
|
|
<button type="submit">Login</button>
|
|
</form>
|