Dodanie ekranu logowania, do zrobienia połączyć to z poprzednim projektem z lekcji 2

This commit is contained in:
Adam Łukasik committed 2026-10-05 12:41:37 +02:00
1 parent 83672909f4
commit c198d9d70a
12 files changed
+351

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
<?php
if((!isset($_POST['username'])) || (!isset($_POST['password']))) {
header("Location: ./");
exit();
}
include('config.php');
$conn = mysqli_connect($host, $user, $pass, $dbnm);
session_start();
$stmt = $conn->prepare("SELECT * FROM uzytkownicy WHERE username = ?;");
$stmt->bind_param("s", $_POST["username"]);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows < 1) {
header("Location: ./login.php?error=true");
exit();
}
$cred = $result->fetch_assoc();
if(password_verify($_POST['password'], $cred['password_hash'])) {
$_SESSION['username'] = $cred['username'];
$_SESSION['user_id'] = $cred['id'];
$_SESSION['user_rights_level'] = $cred['rights_level'];
$_SESSION['logged'] = true;
header("Location: ./");
exit();
} else {
header("Location: ./login.php?error=true");
exit();
}
?>