-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.php
79 lines (69 loc) · 2.18 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
File Name: login.php
Authors Name: Scott Montgomery and Nolan Knill
Web Site Name: Survey Site
File Description: The login page of the survey site.
*/
$page_name = "Login";
include "functions/functions.php";
$email = '';
$password = '';
$errors = array();
// if the user submitted the form (with method="post")
if (!empty($_POST)) :
if (empty($_POST['email'])) :
$errors[] = "Please enter your email address.";
endif;
if (empty($_POST['password'])) :
$errors[] = "Please enter your password.";
endif;
//If there are no validation errors attempt to validate the user
if (empty($errors)) :
//Search for the email in the database
$exists = check_user_exists ($_POST['email']);
if ($exists) :
$user_match = check_password_correct($_POST['email'], $_POST['password']);
if ($user_match) : //log our homie in!
$_SESSION['id'] = $user_match;
set_message("success", "Welcome back :)");
header('Location: index.php');
die;
else :
$errors[] = "Invalid username/password combination";
endif;
else :
$errors[] = "That user doesn't exist!";
$email = $_POST['email'];
endif;
else :
//There is an error on the page. Maintain sticky variables.
$email = $_POST['email'];
endif;
endif;
include 'partials/html_header.php';
?>
<body>
<?php include 'partials/header.php'; ?>
<!-- Main Page Content and Sidebar -->
<div class="row">
<!-- Main Blog Content -->
<div class="large-9 columns" role="content">
<h3>
<?php echo $page_name;?>
</h3>
<?php include 'partials/messages.php'; ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<label>E-mail: </label>
<input type="text" name="email" value="<?php echo $email; ?>">
<label>Password: </label>
<input type="password" name="password">
<input class="button" type="submit" value="Login">
</form>
<p>New user? <a href="register.php" id="register">Register Now</a> to create and manage surveys!</p>
</div>
<?php include 'partials/sidebar.php' ?>
</div>
<?php include 'partials/footer.php'; ?>
</body>
</html>