-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
login.php
47 lines (45 loc) · 1.28 KB
/
login.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
<?php
session_start();
include('includes/connection.php');
if (isset($_POST['login'])) {
$username = $_POST['user_name'];
$password = $_POST['user_password'];
mysqli_real_escape_string($conn, $username);
mysqli_real_escape_string($conn, $password);
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($conn , $query) or die (mysqli_error($conn));
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$user = $row['username'];
$pass = $row['password'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
$role= $row['role'];
$image = $row['image'];
if (password_verify($password, $pass )) {
$_SESSION['id'] = $id;
$_SESSION['username'] = $user;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$_SESSION['email'] = $email;
$_SESSION['role'] = $role;
$_SESSION['image'] = $image;
header('location: admin');
}
else {
echo "<script>alert('invalid username/password');
window.location.href= 'index';</script>";
}
}
}
else {
echo "<script>alert('invalid username/password');
window.location.href= 'index';</script>";
}
}
else {
header('location: index');
}
?>