/
admin_home.php
66 lines (46 loc) · 1.37 KB
/
admin_home.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
<?php
// include function files for this application
require_once('food_galaxy_fns.php');
session_start();
//create short variable names
$username = $_POST['username'];
$passwd = $_POST['passwd'];
if ($username && $passwd) {
// they have just tried logging in
$id = admin_login($username, $passwd);
if($id != -1){
$_SESSION['valid_admin'] = $username;
$_SESSION['name'] = $username;
do_html_header('Home Page');
echo '<div class="form-group" id="success_message">
<div class="col-sm-offset-2 col-sm-8">
<div class="alert alert-success">
<h3> Administrator log in Success! Now, you can manage the system! </h3>
</div>
</div>
</div>';
}
else{
echo '<div class="form-group" id="success_message">
<div class="col-sm-offset-2 col-sm-8">
<div class="alert alert-danger">
<h3> logged in Failure. <a href="login.php">Click here to log in again</a></h3>
</div>
</div>
</div>';
}
}
do_html_footer();
?>
<?php
function admin_login($username, $password, $type) {
include_once('db_fns.php');
$conn = db_connect();
$result = $conn->query("select * from admin
where username = '".$username."'
and password = sha1('".$password."')");
if(!$result) return -1;
if($result->num_rows>0) return 0;
return -1;
}
?>