-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
114 lines (102 loc) · 3.29 KB
/
index.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
<?php
require_once 'user_account.php';
ini_set('session.gc_maxlifetime', 60 * 60); // one hour
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="test page" />
<title>Test Page</title>
</head>
<body>
<div>
<?php
if (isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true &&
isset($_SESSION['user'])){
?>
<ul>
<li>
<span>Welcome back, "<?= $_SESSION['user'] ?>"</span>
<form action="logout.php" method="post">
<input type="submit" value="Log Out" />
<input type="hidden" value="/index.php" name="returnto" />
</form>
</li>
</ul>
<?php
}
// if username and password were saved in cookie, check them
else if (isset($_COOKIE['user']) && isset($_COOKIE['pass']))
{
// if username and password are valid, log user back in
if (login($_COOKIE['user'], $_COOKIE['pass']) == LOGIN_SUCCESS)
{
// remember that user's logged in
$_SESSION['authenticated'] = true;
echo $_SESSION['authenticated'];
// re-save username and, ack, password in cookies for another day
setcookie("user", $_COOKIE['user'], time() + 1 * 24 * 60 * 60);
setcookie("pass", $_COOKIE['pass'], time() + 1 * 24 * 60 * 60);
?>
<ul>
<li>
<span>Welcome back, "<?= $_COOKIE['user'] ?>"</span>
<form action="logout.php" method="post">
<input type="submit" value="Log Out" />
<input type="hidden" value="/index.php" name="returnto" />
</form>
</li>
</ul>
<?php
}
else {
?>
<ul>
<form action="login.php" method="post">
<li id="login">
Login<input type="text" value="" name="user" size="16" />
PW <input type="text" value="" name="pass" size="16" />
<input type="checkbox" name="keep" /><label for="keep">Stay logged in</label>
<input type="hidden" value="/index.php" name="returnto" />
<input type="submit" value="Log In" />
</li>
</form>
</ul>
<?php
}
}
else {
?>
<ul>
<form action="login.php" method="post">
<li id="login">
Login<input type="text" value="" name="user" size="16" />
PW <input type="text" value="" name="pass" size="16" />
<input type="checkbox" name="keep" /><label for="keep">Stay logged in</label>
<input type="hidden" value="/index.php" name="returnto" />
<input type="submit" value="Log In" />
</li>
</form>
</ul>
<?php
}
?>
</div>
<h3>Heading</h3>
<div>
<nav>
<ul>
<li><a href="classes.html">Classes</a></li>
<li><a href="cheatsheet.php">Cheat Sheet</a></li>
<li><a href="sqltest.php">MySQL Test</a></li>
<li><a href="sqlsample.php">MySQL Sample from Textbook</a></li>
</ul>
</nav>
</div>
<footer>
<p>© 2013 Yong Cho</p>
</footer>
</body>
</html>