forked from startupjing/Tech_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PassVariable.php
64 lines (47 loc) · 1.27 KB
/
PassVariable.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
<?php
//PassVariable.php?name=Alice
$name = $_GET['name'];
printf("<p>Hello, %s</p>", htmlentities($name));
?>
<!-- POST form -->
<form action="PassVariable.php" method="POST">
<p>
<label for="nameinput">Name:</label>
<input type="text" name="name" id="nameinput" />
</p>
<p>
<strong>Gener:</strong>
<input type="radio" name="gender" value="male" id="maleinput" /><label for="maleinput">Male</label>
<input type="radio" name="gender" value="female" id="femaleinput" /><label for="femaleinput">Female</label>
</p>
<p>
<input type="submit" value="send" />
<input type="reset" />
</p>
</form>
<?php
$name = $_POST['name'];
$gender = $_POST['gender'];
printf("<p>Hello, %s, you are %s", htmlentities($name), htmlentities($gender));
?>
<!-- self submitting form -->
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']; ?>)" method="POST">
<input type="text" name="name" id="name" />
<input type="submit" value="submit" />
</form>
<?php
if(isset($_POST['name'])){
printf("<p>Hello, %s</p>", htmlentities($_POST['name']));
}
?>
<!-- using session -->
<?php
session_start();
$old_num = (int) @$_SESSION['inc_num'];
if($old_num < 1){
$old_num = 1;
}
$new_num = $old_num * 2;
echo $new_num;
$_SESSION['inc_num'] = $new_num;
?>