1#Get Method and Post Data
2
3Send data through get and Post
4
5$_GET Example
6============
7<?php
8if(isset($_GET['name'])){
9echo htmlentities($_GET['name']);
10//or
11//$name = htmlentities($_GET['name']);
12//echo $name
13print_r($_GET);
14}
15?>
16<!DOCTYPE html>
17<html>
18<head>
19 <title>Get post website</title>
20 </head>
21<body>
22 <form method="GET action=get_post.php">
23 <div>
24 <label>Name</label><br>
25 <input type="text" name ="name">
26 </div>
27 <div>
28 <label>Email</label><br>
29 <input type="text" name ="email">
30 </div>
31 <input type="submit" value ="Submit">
32 </form>
33</body>
34</html>
35================
36$_POST Example
37================
38<?php
39if(isset($_GET['name'])){
40//echo htmlentities($_GET['name']);
41//or
42//$name = htmlentities($_GET['name']);
43//echo $name
44//print_r($_GET);
45}
46
47if(isset($_POST['name'])){
48 $name = htmlentities($_POST['name']);
49 echo $name;
50 print_r($_POST);
51}
52?>
53<!DOCTYPE html>
54<html>
55<head>
56 <title>Get post website</title>
57 </head>
58<body>
59 <form method="POST" action="get_post.php">
60 <div>
61 <label>Name</label><br>
62 <input type="text" name ="name">
63 </div>
64 <div>
65 <label>Email</label><br>
66 <input type="text" name ="email">
67 </div>
68 <input type="submit" value ="Submit">
69 </form>
70</body>
71</html>
72================
73$_REQUEST Example //another uncommon way to do it. This is not
74 //normally done this way
75================
76<?php
77if(isset($_REQUEST['name'])){
78 $name = htmlentities($_REQUEST['name']);
79 echo $name;
80 print_r($_REQUEST);
81}
82
83?>
84<!DOCTYPE html>
85<html>
86<head>
87 <title>Get post website</title>
88 </head>
89<body>
90 <form method="POST" action="get_post.php">
91 <div>
92 <label>Name</label><br>
93 <input type="text" name ="name">
94 </div>
95 <div>
96 <label>Email</label><br>
97 <input type="text" name ="email">
98 </div>
99 <input type="submit" value ="Submit">
100 </form>
101</body>
102</html>
103================
104$_SERVER['QUERY_STRING'] Example
105================
106<?php
107echo $_SERVER['QUERY_STRING'];
108
109
110?>
111<!DOCTYPE html>
112<html>
113<head>
114 <title>Get post website</title>
115 </head>
116<body>
117 <form method="POST" action="get_post.php">
118 <div>
119 <label>Name</label><br>
120 <input type="text" name ="name">
121 </div>
122 <div>
123 <label>Email</label><br>
124 <input type="text" name ="email">
125 </div>
126 <input type="submit" value ="Submit">
127 </form>
128</body>
129</html>
1<?php
2
3 // if your url is http://link?var=value
4
5if (isset($_GET['var'])) // works with request
6 $var = $_GET['var'];
7echo $var;
8
9// output value
10
1<form action="/" method="get">
2 <input type="text" name="name">
3 <br>
4 <input type="submit">
5</form>
6<?php
7 echo $_GET["query"];
8?>