-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogowanie.php
52 lines (44 loc) · 1.26 KB
/
logowanie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
session_start();
if (isset($_POST['zaloguj'])) {
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$stmt = $pdo->prepare("SELECT * FROM uzytkownicy WHERE login = :login");
$stmt->execute(['login' => $_POST['login']]);
$wynik = $stmt->fetch();
if ($wynik && password_verify($_POST['haslo'], $wynik['haslo'])) {
$_SESSION['zalogowany'] = 'tak';
$_SESSION['id'] = $wynik['id'];
header("Location: index.php");
exit();
} else {
$komunikat = "Wprowadzono zły login lub hasło.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Logowanie</title>
<meta charset="utf-8">
</head>
<body>
<?php if (!empty($komunikat)) : ?>
<p style="font-weight: bold; color: red;"><?= $komunikat ?></p>
<?php endif; ?>
<form method="post" action="">
<table>
<tr>
<td>Login</td>
<td><input type="text" name="login" /></td>
</tr>
<tr>
<td>Hasło</td>
<td><input type="password" name="haslo" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="zaloguj" value="Zaloguj" /></td>
</tr>
</table>
</form>
</body>
</html>