mirror of
https://github.com/Alvin-Zilverstand/school.git
synced 2026-04-18 06:48:44 +02:00
:3
This commit is contained in:
42
projects/challenge 9/Spik-en-span/php/process_login.php
Normal file
42
projects/challenge 9/Spik-en-span/php/process_login.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
$servername = "localhost";
|
||||
$username = "database12";
|
||||
$password = "181t$1lJg";
|
||||
$dbname = "spik_en_span";
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$username = isset($_POST['username']) ? trim(htmlspecialchars($_POST['username'])) : '';
|
||||
$password = isset($_POST['password']) ? trim(htmlspecialchars($_POST['password'])) : '';
|
||||
|
||||
$sql = "SELECT id, password_hash FROM employees WHERE username = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("s", $username);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($user_id, $password_hash);
|
||||
$stmt->fetch();
|
||||
} else {
|
||||
header("Location: ../employee-login.html?error=server_error");
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
if ($password_hash && password_verify($password, $password_hash)) {
|
||||
session_start();
|
||||
$_SESSION['user_id'] = $user_id;
|
||||
header("Location: ");
|
||||
exit();
|
||||
} else {
|
||||
header("Location: ../employee-login.php?error=invalid_credentials");
|
||||
exit();
|
||||
}
|
||||
} finally {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user