-
Notifications
You must be signed in to change notification settings - Fork 525
/
13_sessions.php
48 lines (43 loc) · 1.13 KB
/
13_sessions.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
<?php
/* ------------ Sessions ------------ */
/*
Sessions are a way to store information (in variables) to be used across multiple pages.
Unlike cookies, sessions are stored on the server.
*/
session_start(); // Must be called before accessing any session data
if (isset($_POST['submit'])) {
$username = filter_input(
INPUT_POST,
'username',
FILTER_SANITIZE_FULL_SPECIAL_CHARS
);
$password = filter_input(
INPUT_POST,
'password',
FILTER_SANITIZE_FULL_SPECIAL_CHARS
);
if ($username == 'brad' && $password == 'password') {
// Set Session variable
$_SESSION['username'] = $username;
// Redirect user to another page
header('Location: /php-crash/extras/dashboard.php');
} else {
echo 'Incorrect username or password';
}
}
?>
<form action="<?php echo htmlspecialchars(
$_SERVER['PHP_SELF']
); ?>" method="POST">
<div>
<label>Username: </label>
<input type="text" name="username">
</div>
<br>
<div>
<label>Password: </label>
<input type="password" name="password">
</div>
<br>
<input type="submit" name="submit" value="Submit">
</form>