34968-vm/login_process.php
Flatlogic Bot ab1ae8b39b V2
2025-10-14 23:38:25 +00:00

37 lines
981 B
PHP

<?php
session_start();
require_once 'db/config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$password = $_POST['password'];
if (empty($email) || empty($password)) {
die('Please fill all required fields.');
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
die('Invalid email format.');
}
try {
$pdo = db();
$sql = "SELECT * FROM users WHERE email = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
header("Location: index.php");
exit;
} else {
die('Invalid email or password.');
}
} catch (PDOException $e) {
die("Could not connect to the database $dbname :" . $e->getMessage());
}
}
?>