-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
136 lines (117 loc) · 5.77 KB
/
login.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
session_start();
if (isset($_SESSION['email'])) {
header('Location: index.php');
exit;
}
include('config/db_connect.php');
$email = $password = $id = '';
$errors = array('email' => '', 'password' => '');
if (isset($_POST['login'])) {
//Checking Email
if (empty($_POST['email'])) {
$errors['email'] = 'Email id must be entered <br />';
} else {
$email = $_POST['email'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email = '';
$errors['email'] = 'Invalid email or password <br />';
} else {
$email = mysqli_real_escape_string($conn, $_POST['email']);
$sql = "SELECT user_id FROM user_details WHERE email='$email'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
if(!$count) {
$errors['email'] = 'Invalid email or password <br />';
}
mysqli_free_result($result);
}
}
//Checking Password
if (empty($_POST['password'])) {
$errors['password'] = 'Password must be entered <br />';
} else {
$password = $_POST['password'];
if (strlen($password) < 8) {
$password = '';
$errors['password'] = 'Invalid email or password <br />';
} else {
$password = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT user_id FROM user_details WHERE email='$email' AND password='$password'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
$row = mysqli_fetch_assoc($result);
$id = $row['user_id'];
if(!$count) {
$errors['email'] = 'Invalid email or password <br />';
$errors['password'] = 'Invalid email or password <br />';
}
mysqli_free_result($result);
}
}
if (!array_filter($errors)) {
$_SESSION['email'] = $email;
$_SESSION['id'] = $id;
header('Location: index.php');
}
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Booklyst</title>
<style>
.card-image {
width: 25% !important;
height: 25% !important;
}
.card-style {
width: 50% !important;
}
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="bg-light">
<div class="container">
<div class="row h-100">
<div class="card rounded card-style mx-auto my-auto">
<img src="img/logo.png" class="card-img-top img-fluid card-image mx-auto d-block my-3">
<div class="car-body">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" class="container" method="POST">
<div class="input-group px-5 mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary disabled btn-primary" type="button">
<i class="fa fa-user"></i>
</button>
</div>
<label for="email" class="sr-only">Email id</label>
<input type="text" class="form-control" name="email" placeholder="Enter Your Email" value="<?php echo $email ?>">
<div class="text-danger input-group mb-2"><?php echo $errors['email']; ?></div>
</div>
<div class="input-group px-5 mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary disabled btn-primary" type="button">
<i class="fa fa-lock"></i>
</button>
</div>
<label for="password" class="sr-only">Password</label>
<input type="password" class="form-control" name="password" placeholder="Enter Your Password" value="<?php echo $password ?>">
<div class="text-danger input-group mb-2"><?php echo $errors['password']; ?></div>
</div>
<p class="card-text text-center mb-1"><a href="forgot_password.php" class="card-link">Forgot Pasword?</a></p>
<p class="card-text text-center">Don't have an account? <a href="register.php" class="card-link">Register</a></p>
<button type="submit" name="login" class="btn btn-primary mb-3 mx-auto d-block"><i class="fa fa-send mr-3"></i><b>Login</b></button>
</form>
</div>
</div>
</div>
</div>
<!-- required scripts for BS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>