-
Notifications
You must be signed in to change notification settings - Fork 1
/
index1.php
245 lines (193 loc) · 8.01 KB
/
index1.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
require("common.php");
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
//echo "db is connected";
}
// This variable will be used to re-display the user's username to them in the
// login form if they fail to enter the correct password. It is initialized here
// to an empty value, which will be shown if the user has not submitted the form.
$submitted_username = '';
// check to determine whether the login form has been submitted
// If it has, then the login code is run, otherwise the form is displayed
if (!empty($_POST)) {
// This query retreives the user's information from the database using their username.
$query = "SELECT username, password FROM userinfo WHERE username = :username";
// The parameter values
$query_params = array(
':username' => $_POST['username']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch (PDOException $ex) {
die("Failed to run query: " . $ex->getMessage());
}
// This variable tells us whether the user has successfully logged in or not.
$login_ok = false;
// Retrieve the user data from the database. If $row is false, then the username is not registered.
$row = $stmt->fetch();
if ($row) {
$check_password = $_POST['password'];
if ($check_password === $row['password']) {
$login_ok = true;
}
}
// If the user logged in successfully, then we send them to the private members-only page
// Otherwise, we display a login failed message and show the login form again
if ($login_ok) {
// Here I am preparing to store the $row array into the $_SESSION by
// removing the salt and password values from it. Although $_SESSION is
// stored on the server-side, there is no reason to store sensitive values
// in it unless you have to. Thus, it is best practice to remove these
// sensitive values first.
//unset($row['salt']);
unset($row['password']);
// This stores the user's data into the session at the index 'user'.
// We will check this index on the private members-only page to determine whether
// or not the user is logged in. We can also use it to retrieve
// the user's details.
session_start();
$_SESSION['user'] = $row;
$_SESSION['username'] = $_POST["username"];
// Redirect the user to the private members-only page.
header("Location: instructions1.php");
die("Redirecting to: instructions1.php");
} else {
print("Login Failed.");
// Show them their username again so all they have to do is enter a new
// password. The use of htmlentities prevents XSS attacks. You should
// always use htmlentities on user submitted values before displaying them
// to any users (including the user that submitted them). For more information:
// http://en.wikipedia.org/wiki/XSS_attack
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}
}
?>
<!DOCTYPE html><html lang="en">
<head>
<!-- Basic informations -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Site informations -->
<title>TeleHealth Login</title>
<meta name="author" content="Sabrina Han">
<!-- Open Graph -->
<meta property="og:title" content="Free Aurora Template">
<meta property="og:description" content="Free HTML5 Template created by Dominik Serafin.">
<meta property="og:url" content="http://serafin.io/aurora-template/">
<meta property="og:image" content="http://serafin.io/aurora-template/content/og_image.png">
<!-- Fonts -->
<link href="style/fonts/webfont-raleway/webfont-raleway.css" rel="stylesheet" type="text/css">
<link href="style/fonts/webfont-font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css">
<!-- Stylesheets -->
<link href="style/css/global.css" type="text/css" rel="stylesheet" media="all">
<!-- Scripts preload -->
<!--[if lt IE 9]><script src="style/js/html5shiv.js"></script><![endif]-->
<style>
.button {
background-color: transparent;
border: none;
color: white;
padding: 15px 60px 15px 60px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 24px;
cursor: pointer;
}
input[type=text] {
width: 80%;
padding: 12px 18px;
background-color: transparent;
margin: 8px 0;
box-sizing: border-box;
border: 3px solid #ccc;
-webkit-transition: 0.5s;
transition: 0.5s;
outline: none;
}
input[type=password] {
width: 80%;
padding: 12px 18px;
background-color: transparent;
margin: 8px 0;
box-sizing: border-box;
border: 3px solid #ccc;
-webkit-transition: 0.5s;
transition: 0.5s;
outline: none;
}
img {
border-radius: 50%;
}
.hero__background1 {
position: absolute;
top: 0;
left: 0;
z-index: -400;
width: 100%;
height: 100%;
background-image: url("../img/hero_background.jpg");
background-repeat: repeat;
}
</style>
</head>
<body>
<!-- Some Helper Stuff -->
<div id="start" class="start"> </div>
<div class="maxwidth1050"> </div>
<!-- Header -->
<header class="header">
<div class="header__wrapper">
<div class="header__hamburger">
<div class="header__hamburger-block"> </div>
<div class="header__hamburger-block"> </div>
<div class="header__hamburger-block"> </div>
</div>
<a href="#start" class="header__title-wrapper js-smooth-scroll">
<div class="header__title-main">Tele Health</div>
<div class="header__title-sub">By School of Health and Rehabilitation</div>
</a>
</div>
</header>
<!-- End Header -->
<section id="hero" class="hero">
<div class="hero__background1"> </div>
<div class="hero__gradient"> </div>
<!--<div class="hero__pattern"> </div>-->
<div class="hero__content">
<div class="hero__content-wrapper">
<div class="hero__title-wrapper">
<div class="hero__title-large">TeleHealth </div>
<div class="hero__title-small">Log in here</div>
<!-- <div class="hero__title-small">This is the Aurora Template.</div> -->
</div>
<div margin-top = "90px" float = "right">
<div class="hero__photo-wrapper">
<img src="download.png" alt="healthlog" height = "220px" width = "220px" background-size="cover">
</div>
</div>
<form action="index1.php" method="post">
<div class="hero__description">
<label>Username:</label>
<input class="form-control" type="text" name="username" value="<?php echo $submitted_username; ?>" />
<br> </br>
<label>Password:</label>
<input class="form-control" type="password" name="password" />
<p style="text-align: right;"> <span class="psw"> <a href="keyterms.html">Forgot password?</a></span> </p>
<p style="text-align: right;"> <span class="psw"> <a href="adminlogin1.php">Log in as Administrator</a></span> </p>
</div>
<div class="hero__call-to-action">
<!-- <p style="text-align: center;"> <button type="submit" class="btn btn-default">Submit</button> </p>
<p style="text-align: center;"> <button type="submit" class="btn btn-default" onclick = "window.open('signup.php')" >Register</button> </p> -->
<a class="hero__button ghost-button ghost-button--hero"> <button type="submit" class = "button"> Submit </button> </a>
<a href= "register1.php" class="hero__alt-button"> or Register</a>
</div>
</form>
</div>
</div>
</section>