-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
62 lines (53 loc) · 2.06 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
<?php
include 'header.php';
if(isset($_SESSION['logged_in'])){
header("location: index.php");
ob_end_flush();
}
if(isset($_POST['login'])){
$email = $_POST['email'];
$pass = $_POST['password'];
$check = $conn->prepare("SELECT * FROM users WHERE user_email = ?");
$check->execute([$email]);
foreach($check as $value){
if($value['user_email'] == $email && password_verify($pass, $value['user_pass'])){
$_SESSION['logged_in'] = true;
$_SESSION['u_id'] = $value['user_id'];
header("location: index.php");
}else{
$msg = "Password incorrect!";
header("Location: login.php?msg=$msg");
}
}
}
?>
<div class="container">
<div class="row justify-content-center">
<div class="col-6 shadow p-4 mt-4">
<?php if (isset($_GET['msg'])) { ?>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong><?= $_GET['msg']; ?></strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php } ?>
<form method="POST" action="login.php">
<div class="row mb-3">
<label for="email" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email">
</div>
</div>
<div class="row mb-3">
<label for="pass" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pass" name="password">
</div>
</div>
<button type="submit" class="btn btn-primary" name="login">Sign in</button>
<a class="btn btn-success" href="register.php">Register</a>
</form>
</div>
</div>
</div>
</body>
</html>