-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticate.php
86 lines (45 loc) · 1.72 KB
/
authenticate.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
<?php
require 'dbconnection.php';
session_start();
class authenticate{
private $uname;
private $pwd;
private $conn;
private $errorMsg;
function __construct() {
$this->conn= new dbconnection();
}
public function login(){
$uname=filter_input(INPUT_POST, uname);
$pwd= filter_input(INPUT_POST,pwd);
$query="SELECT * FROM users WHERE uname=:uname and pwd= :pwd";
if(isset($uname) && isset($pwd)){
$this->conn->query($query);
$this->conn->bind(':uname',$uname);
$this->conn->bind(':pwd',$pwd);
$this->conn->execute();
$rs=$this->conn->resultSet();
if ($rs){
if($uname=='admin'){
$_SESSION['user']='admin';
header("Location: admin.php");
}else {
$_SESSION['user']='staff';
header("Location: front_desk.php");
}
}else {
$errorMsg= 'invalid username/password';
$this->loginErr($errorMsg);
}
}else {
$errorMsg= 'All fields required!';
$this->loginErr($errorMsg);
}
}
public function loginErr($errorMsg){
$_SESSION['message']=$errorMsg;
header("Location: index.php");
}
}
$auth=new authenticate();
$auth->login();