Database conn, users in progress
This commit is contained in:
29
login.php
Normal file
29
login.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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>
|
||||
Reference in New Issue
Block a user