-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
124 lines (82 loc) · 3.32 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
<!-- In the login page we check if user exist in database we then log in
and user automatically moved to welcome page.
If not exist then show error that user not exist -->
<?php
$login = 0;
$invalid = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
include 'connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
//just see where username and password both matches
$sql = "select * from `registration` where username ='$username' and password ='$password'";
$result = mysqli_query($con, $sql);
// checks that the user exist in the database or not
// if exist then shows success message on top
if ($result) {
$num = mysqli_num_rows($result);
if ($num > 0) {
$login = 1;
session_start();
$_SESSION['username'] = $username;
echo "<script>
window.location.href = 'login.php';
</script>";
}
// if not exist then it shows error
else {
$invalid = 1;
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Login Page</title>
</head>
<body>
<?php
if ($login) {
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success </strong> User Logged in.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
if ($invalid) {
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Invalid </strong> User does not exist.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<div class="container mt-5">
<form action="login.php" method="post">
<h1 class="mb-5">login page</h1>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control " id="exampleInputEmail1" aria-describedby="emailHelp"
placeholder="Enter email" name="username" required>
</div>
<div class="form-group mt-3">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" placeholder="Enter Password" name="password" required>
</div>
<button type="submit" class="btn btn-primary w-15 mt-3">login</button>
<div class="container mt-5">
<p class="mt-6">If you don't have an account click create account.</p>
<a href="sign.php" class="btn btn-primary w-20 ">Create account</a>
</div>
</form>
</div>
</body>
</html>