-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
67 lines (59 loc) · 1.89 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
<?php include 'includes/connection.php';?>
<?php include 'includes/header.php';?>
<?php include 'includes/navbar.php';?>
<?php
session_start();
if (isset($_POST['login'])) {
$username = $_POST['user'];
$password = $_POST['pass'];
mysqli_real_escape_string($conn, $username);
mysqli_real_escape_string($conn, $password);
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($conn , $query) or die (mysqli_error($conn));
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$user = $row['username'];
$pass = $row['password'];
$name = $row['name'];
$email = $row['email'];
$role= $row['role'];
$course = $row['course'];
if (password_verify($password, $pass )) {
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['role'] = $role;
$_SESSION['course'] = $course;
header('location: dashboard/');
}
else {
echo "<script>alert('invalid password');
</script>";
header('location: login.php');
}
}
}
else {
echo "<script>alert('username doesn't exist');
window.location.href= 'login.php';</script>";
}
}
?>
<body style="background-image: url('images/loginbg.jpg');">
<div class="login-card" style="justify-content: center";>
<h1>Log-in</h1><br>
<form method="POST">
<input type="text" name="user" placeholder="Username" required="">
<input type="password" name="pass" placeholder="Password" required="">
<input type="submit" name="login" class="login login-submit" value="login">
</form>
<div class="login-help">
<a href="signup.php">Register</a> • <a href="recoverpassword.php">Forgot Password</a>
</div>
</div>
<script src='css/jquery.min.js'></script>
<script src='css/jquery-ui.min.js'></script>
</body>
</html>