-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.php
50 lines (43 loc) · 1.13 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
<?php
session_start();
include "db_conn.php";
if(isset($_POST['uname']) && isset($_POST['password'])) {
function validate($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return data;
}
}
$uname = validate($_POST['uname']);
$pass = validate($_POST['password']);
if(empty($uname)){
header("Location: loginIndex.html?error=User Name is required");
exit();
}
else if(empty($pass)){
header("Location: loginIndex.html?error=Password is required");
exit();
}
$sql = "SELECT * FROM users WHERE user_name='$uname' AND password='$pass'";
$result = mysqli_query($conn, sql);
if(mysqli_num_row($result) === 1) {
$row = mysqli_fetch_assoc($result);
if($row['user_name'] === $uname && $row['password'] === $pass) {
echo "Logged In!";
$_SESSION['user_name'] = $row['user_name'];
$_SESSION['name'] = $row['name'];
$_SESSION['id'] = $row['id'];
header("Location: homePage.html");
exit();
}
else{
header("Location: loginIndex.html?error=Incorrect User Name or Password");
exit();
}
}
else{
header("Location: loginIndex.html");
exit();
}
?>