-
Notifications
You must be signed in to change notification settings - Fork 1
/
login_check.php
45 lines (43 loc) · 1.66 KB
/
login_check.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
<?php
session_start();
if (isset($_POST['submit'])) {
require "connection.php";
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$stmt = $conn->prepare($sql);
$stmt->execute();
if ($stmt->rowCount()>0) {
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result['status'] == 'pending') {
header("location:index.php?status=pending");
}
if ($result['user_role'] == 'admin' && $result['status'] == 'approved') {
$_SESSION['user_session'] = [
'user_id' => $result['user_id'],
'username' => $result['username'],
'first_name'=> $result['first_name'],
'last_name' => $result['last_name'],
'email' => $result['email'],
'status' => $result['status'],
'user_role' => $result['user_role']
];
header("location:admin/index.php?status=success");
}
elseif ($result['user_role'] == 'user' && $result['status'] == 'approved') {
$_SESSION['user_session'] = [
'user_id' => $result['user_id'],
'username' => $result['username'],
'first_name'=> $result['first_name'],
'last_name' => $result['last_name'],
'email' => $result['email'],
'status' => $result['status'],
'user_role' => $result['user_role']
];
header("location:index.php?status=success");
}
}
else {
header("location:login.php?status=error");
}
}