-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginstaff.php
executable file
·70 lines (59 loc) · 1.64 KB
/
loginstaff.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
<?php
require('values.php');
require('functions.php');
html_header("Staff Login");
?>
<body >
<DIV class=header>
<A HREF="#"><IMG style="width:500px; height:100px; margin:15px;" src="img/logo.png"></A>
</DIV>
<?php
if(!isset($_POST['submit'])) //if user has not hit Submit
{
login_form("","","staff");
} //if user has not hit submit
else //user Has hit submit, check validity.
{
$username = $_POST['user'];
$password = $_POST['pass'];
$username= trim($username);
if( empty($username))
{ try_again("Please enter a username.",$username,"staff");}
else if( empty($password))
{ try_again("Please enter a password.",$username,"staff");}
else try
{
//open db
$db = new PDO(DB_PATH, DB_LOGIN, DB_PW);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "select count(*) from login_staff where username = '$username' and password = '$password'";
$result = $db->query($sql)->fetch();
if( $result[0] == 0)
{
//you were just plain wrong.
try_again("Username/password pair not found.",$username,"staff");
}
else
{
//you had a valid login
// get TA ID and name for the entire session.
session_start();
$_SESSION['name'] = $username;
$sql = "select department from login_staff where username = \"$username\";";
$result = $db->query($sql)->fetch();
$_SESSION['dept'] = $result['department'];
// go to next page.
session_regenerate_id(true);
session_write_close();
header("Location:quarterstaff.php");
exit();
}
}
catch(PDOException $e)
{
puts('Exception : '.$e->getMessage());
$db = NULL;
}
} //check user creds
?>
</html>