-
Notifications
You must be signed in to change notification settings - Fork 1
/
login-auth.php
53 lines (47 loc) · 1.23 KB
/
login-auth.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
<?php
/*
* Script to authenticate and log in the user.
* Errors will be produced if the user with the given username
* and password does not exist in the database.
*/
include_once('db_connect.php');
$username = $_POST['username'];
$password = md5($_POST['password']);
//$referer = $_POST['referer'];
$redirect = null;
$append = null;
if($_POST['location'] != '') {
$redirect = $_POST['location'];
}
if (array_key_exists('append', $_POST) ){
$append = $_POST['append'];
}
$result = $db->prepare("SELECT * FROM user WHERE username=? AND password=?;");
$result->execute(array($username, $password));
session_start();
if ($result->rowCount() != 0) {
$user = $result->fetch();
$_SESSION['username'] = $user['username'];
$_SESSION['user_id'] = $user['id'];
$_SESSION['users_name'] = $user['fname'] . " " . $user['lname'];
if($redirect) {
header("Location:". $redirect);
}
else {
header("Location:index.php");
}
} else {
$_SESSION['login_failed'] = true;
if($redirect) {
header("Location:login.php?location=". $redirect);
}
else {
header("Location:login.php");
}
}
?>
<html>
<head>
<script type="text/javascript"> sessionStorage.clear()</script>
</head>
</html>