-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
76 lines (67 loc) · 2.4 KB
/
index.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
<?php
session_start();
include "config/connection.php";
if(isset($_SESSION['username'])){
if($_SESSION['username'] == 'admin1' || $_SESSION['username'] == 'admin'){
header('Location: admin-page.php');
}
else{
header('Location: user.php');
}
}
$errors = array('username' => '', 'password' => '', 'authenticate' => '');
$username = $password = '';
if(isset($_POST['signin'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username)){
$errors['username'] = 'Username is required';
}
if(empty($password)){
$errors['password'] = 'Password is required';
}
if(! array_filter($errors)){
$username = $conn->real_escape_string($username);
$password = $conn->real_escape_string($password);
//CHECK CORRECT USERNAME PASSWORD
$query1 = "CALL check_user_credentials('$username', '$password')";
if ($conn->query($query1) === FALSE) {
$errors['authenticate'] .= $conn->error;
}
else{
$_SESSION['username'] = $username;
header('Location: user.php');
}
$conn->close();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include "template/header.php" ?>
<div style="margin-top:100px;">
<form action="index.php" method="POST">
<h3 class="heading">Welcome to eRail</h3>
<label>
<p class="label-txt">ENTER YOUR USERNAME</p>
<input type="text" class="input" name="username" value="<?php echo htmlspecialchars($username) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['username'])?></p>
</label>
<label>
<p class="label-txt">ENTER YOUR PASSWORD</p>
<input type="password" class="input" name="password" value="<?php echo htmlspecialchars($password) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['password'])?></p>
</label>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['authenticate'])?></p>
<button type="submit" name="signin" value="submit">Sign-In</button>
<a href="register.php" class="register">Not A Member? Register</a>
</form>
</div>
<?php include "template/footer.php" ?>
</html>