-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprijava.php
59 lines (53 loc) · 1.73 KB
/
prijava.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
53
54
55
56
57
58
59
<?php
require ('baza.php');
require('nav.php');
$error = false;
?>
<div class="container mt-5 form-container">
<h2 class="mb-5">Prijava</h2>
<form action="" method="post">
<div class="form-group">
<label for="email">Korisničko ime:</label>
<input type="text" class="form-control" id="username" name="username" required />
</div>
<div class="form-group">
<label for="password">Lozinka:</label>
<input type="password" class="form-control" id="password" name="password" required/>
</div>
<input type="submit" class="btn btn-primary" name="submit" value="Prijava">
<?php if (isset($_GET["error"])): ?>
<div class="alert alert-danger mt-4" role="alert">
Prijava je neuspješna, pokušajte sa drugim korisničkim imenom i lozinkom.
</div>
<?php endif ?>
</form>
</div>
<?php
if (isset($_POST['submit'])) {
if (isset($_POST["username"]) && isset($_POST["password"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "Select id from korisnik where korisnicko_ime='" . $username ."'";
$result = $con->query($sql);
$row = $result->fetch_object();
if (!$row) {
header('Location: prijava.php?error=1');
}
$sql = "Select k.id, k.lozinka, tk.naziv from korisnik k JOIN tip_korisnika tk where k.tip_korisnika_id = tk.id
AND k.id='" . $row->id. "'";
$result = $con->query($sql);
$row = $result->fetch_object();
$hashedPassword = $row->lozinka;
if (password_verify($password, $hashedPassword)) {
$_SESSION["user"] = $row->id;
$_SESSION["role"] = $row->naziv;
header('Location: index.php');
} else {
header('Location: prijava.php?error=1');
}
} else {
header('Location: prijava.php?error=1');
}
}
?>
<?php require('footer.php')?>