This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifyuser.php
99 lines (84 loc) · 2.4 KB
/
verifyuser.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
include 'config.php';
if(isset($_POST['uname']) && isset($_POST['upass'])
&& !empty($_POST['uname']) && !empty($_POST['upass'])){
/// data receive
/// database check email, password
/// yes, forward homepage
/// no, forward loginpage
$var1=$_POST['uname'];
$var2=$_POST['upass']; //md5($_POST['upass']);
try{
///php-mysql 3 way. We will use PDO - PHP data object
$dbcon = new PDO("mysql:host=$dbserver:$dbport;dbname=$db;","$dbuser","$dbpass");
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlquery="SELECT username, user_type, user_id FROM usertable WHERE username='$var1' and user_password='$var2'";
//echo $sqlquery;
try{
$returnval=$dbcon->query($sqlquery);
$table=$returnval->fetchAll();
if($returnval->rowCount()==1){
$usertype=$table[0]['user_type'];
$user_id=$table[0]['user_id'];
///one valid user found
session_start();
$_SESSION['username']=$var1;
$_SESSION['role']=$usertype;
$_SESSION['user_id']=$user_id;
//echo $var1;
//echo $usertype;
if($usertype=='admin'){
?>
<script>
window.location.assign('admin/');
</script>
<?php
}
else if($usertype=='manager'){
?>
<script>
window.location.assign('manager/');
</script>
<?php
}
else if($usertype=='customer'){
?>
<script>
window.location.assign('customer/');
</script>
<?php
}
}
else{
///invalid user
?>
<script>
window.location.assign('login.php');
</script>
<?php
}
}
catch(PDOException $ex){
?>
<script>
window.location.assign('login.php');
</script>
<?php
}
}
catch(PDOException $ex){
?>
<script>
window.location.assign('login.php');
</script>
<?php
}
}
else{
?>
<script>
window.location.assign('login.php');
</script>
<?php
}
?>