-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession.php
75 lines (66 loc) · 2.1 KB
/
session.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
include 'config.php';
function sanitizeInputS($val) {
include 'config.php';
$sprey1 = mysqli_real_escape_string($conn,$val);
$sprey2 = filter_var ($sprey1, FILTER_SANITIZE_STRING);
$sprey3 = strip_tags($sprey2);
$sprey4 = htmlspecialchars($sprey3);
$sprey5 = trim($sprey4," ");
return $sprey5;
}
session_start();
// $user_check = $_SESSION['login_user'];
$user_check = sanitizeInputS($_SESSION['login_user']);
// $ses_sql = mysqli_query($conn,"select id, email, name, status, role from users where email = '$user_check'");
// $row = mysqli_fetch_array($ses_sql, MYSQLI_ASSOC);
try{
$sql = "select id, email, name, status, role from users where email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $user_check);
$stmt->execute();
$result = $stmt->get_result();
} catch(Exception $e){
if ($debug_mode == true){
// echo $e;
die('debug: '.$e);
}
else{
echo 'error';
die();
}
}
$row = $result->fetch_assoc();
$login_session = $row['email'];
$login_username = $row['name'];
$login_user_id = $row['id'];
if (isset($_SESSION['login_user'])) {
if ($row['role'] == 'user') {
if ($row['status'] == 'true') {
} else {
session_start();
if (session_destroy()) {
header('Location: success.php?p=not_active');
die();
}
}
} elseif ($row['role'] == 'admin') {
if ($row['status'] == 'true') {
header('Location: admin.php');
die();
} else {
session_start();
if (session_destroy()) {
header('Location: success.php?p=not_active');
die();
}
}
} else {
header('Location: login.php');
die();
}
} else {
header('Location: login.php');
die();
}
?>