24 lines
700 B
PHP
24 lines
700 B
PHP
<?php
|
|
session_start();
|
|
require 'db.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$username = htmlspecialchars($_POST['username']);
|
|
$password = $_POST['password'];
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password']) && !$user['disabled']) {
|
|
// Store user ID, username, and role in session
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['role'] = $user['role']; // Store user role
|
|
echo 'success';
|
|
} else {
|
|
echo 'Invalid login credentials';
|
|
}
|
|
}
|
|
?>
|