-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
109 lines (89 loc) · 4.15 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
<?php
//login if account is exists
$login = false; // default false
//error if crenditials mismatch from database
$showError = false;
//if methos formmethos is post
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//for establishing connection to databse server
include 'partials/_dbconnect.php';
//by default alert is false
$username = $_POST['username'];
$password = $_POST['password'];
//sql query for matching username and password with database
$sql = "Select * from users where username = '$username' AND password = '$password'";
$result = mysqli_query($conn,$sql);
//gets number of users accoutn count from database
$num = mysqli_num_rows($result);
//check is user have only one number of account
if($num==1){
$login = true;
//after successfully login session is stared
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['username']= $username;
//now redirectt user using header by giving location of php file
header("Location: welcome.php");
}
else{
//if user password is not match
$showError = "Please Enter Correct Username or Password";
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Login!!</title>
</head>
<body>
<?php require 'partials/_nav.php'?>
<!-- if user created accountat that time showing this alert -->
<?php
if($login){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success!</strong> Congratulations! You Have been logged in !!!!
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
if($showError){
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> '.$showError.'
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
?>
<div class="container">
<h1 class="text-center">Login!!</h1>
<form action="/login-system/login.php" method="post">
<div class="form-group">
<label for="username">UserName</label>
<input type="text" class="form-control" id="username" name="username" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>