-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhidden_variables_solution.php
executable file
·51 lines (48 loc) · 1.55 KB
/
hidden_variables_solution.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
<?php
// Get the value of the submit button using $_GET['name_of_submit_button']
$button = isset($_GET['action']) ? $_GET['action'] : "X";
$counter = isset($_GET['counter']) ? (int) $_GET['counter'] : 0;
// Check to see if name is set
$name_form = "";
if ( isset($_GET['name']) ) {
$name = strip_tags($_GET['name']);
$name_form .= "<b>Hello " . $name . "</b><br>\n";
$name_form .= "<input type=hidden name='name' value='" . $name . "'>\n";
} else {
$name_form .= "<br>Please enter your name:\n";
$name_form .= "<br><input type=text name='name' size=40 maxlength=64>\n";
$name_form .= "<br><input type=submit name='OK' value='OK'>\n";
}
// Test to see if == "+"
if ( $button == "+" ) {
// If so then increment the counter
$counter++;
} elseif ( $button == "-" ) {
// Otherwise decrement the counter
$counter--;
}
?>
<!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 Hidden Variables</title>
</head>
<body>
<h1>Counter Example Using Hidden Variables</h1>
<p> </p>
<form name="Session" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo $name_form; ?>
<table border=0>
<tr><td><input type=submit name="action" value="+"></td>
<td><input type=submit name="action" value="-"></td></tr>
</table>
<input type=hidden name="counter" value="<?php echo @$counter; ?>">
</form>
<br>
<b>COUNTER:</b>
<?php echo $counter; ?>
<br><a href="index.php">BACK</a>
<?php phpinfo(INFO_VARIABLES); ?>
</body>
</html>