-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
48 lines (41 loc) · 1.25 KB
/
test
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
<?php
session_start();
include "db_conn.php";
if (isset($_POST['username']) && isset($_POST['password'])) {
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$uname = validate($_POST['username']);
$pass = validate($_POST['password']);
if (empty($uname)) {
header("Location: index.php?error=User is required");
exit();
} elseif (empty($pass)) {
header("Location: index.php?error=Password is required");
exit();
}
$sql = "SELECT * FROM users WHERE user_name='$uname' AND passwords='$pass'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($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: home.php");
exit();
}
else{
header("Location:index.php?error=Incorrect User Name or Password");
exit();
}
}
}
else {
header("Location: index.php");
exit();
}