-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsession_counter.php
executable file
·63 lines (59 loc) · 1.6 KB
/
session_counter.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
<?php
// Initialize the session
session_start();
if (isset($_GET['logout'])) {
session_destroy();
}
// Get the value of the submit button using $_GET['name_of_submit_button']
$button = isset($_GET['action']) ? $_GET['action'] : "X";
$counter = isset($_SESSION['counter']) ? (int) $_SESSION['counter'] : 0;
// Test to see if == "+"
if ( $button == "+" ) {
// If so then increment the counter
$counter++;
} elseif ( $button == "-" ) {
// Otherwise decrement the counter
$counter--;
}
$_SESSION['counter'] = $counter;
// Process name
$name = "";
if (isset($_SESSION['name'])) {
$name = $_SESSION['name'];
} elseif (isset($_GET['name'])) {
$name = strip_tags($_GET['name']);
$_SESSION['name'] = $name;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Counter Example Using Session</title>
</head>
<body>
<h1>Counter Example Using Session</h1>
<p> </p>
<form name="Session" method=GET>
<?php
if ($name) {
echo "<b>Hello " . htmlspecialchars($name) . "</b><br>\n";
} else {
echo "<br>Please enter your name:\n";
echo "<br><input type=text name='name' size=40 maxlength=64>\n";
echo "<br><input type=submit name='OK' value='OK'>\n";
}
?>
<table border=0>
<tr><td><input type=submit name="action" value="+"></td>
<td><input type=submit name="action" value="-"></td></tr>
</table>
<br><input type=submit name="logout" value="Logout">
</form>
<br>
<b>COUNTER:</b>
<?php echo $counter; ?>
<br><a href="index.php">BACK</a>
<?php phpinfo(INFO_VARIABLES); ?>
</body>
</html>