This document discusses web forms using PHP. It explains how forms send data using the GET and POST methods, and how PHP retrieves form data using the $_GET and $_POST variables. The main differences between GET and POST are described, such as GET having data limits while POST does not, and POST being more secure since data is not appended to the URL. An example form and PHP code is provided to demonstrate retrieving and displaying submitted form data.
3. PHP GET and POST Methods
Before the browser sends the information, it encodes using
a scheme called URL encoding. In this scheme, name/value
pairs are joined with equal signs and different pairs are
separated by the ampersand.
There are two ways the browser client can send information
to the web server.
The GET Method
The POST Method
The PHP $_GET and $_POST variables are
used to retrieve information from forms, like user input.
4. The GET Method
The GET method sends the encoded user information
appended to the page request. The page and the encoded
information are separated by the ? character.
http://www.test.com/index.htm?name1=value1&name2=v
alue2
The GET method is restricted to send upto 1024 characters
only.
Never use GET method if you have password or other
sensitive information to be sent to the server.
GET can't be used to send binary data, like images or word
documents, to the server.
The information is encoded as described in case of GET
method and put into a header called QUERY_STRING.
5. The POST Method
The POST method transfers information via HTTP headers.
The POST method does not have any restriction on data
size to be sent.
The POST method can be used to send ASCII as well as
binary data
The data sent by POST method goes through HTTP header
so security depends on HTTP protocol. By using Secure
HTTP you can make sure that your information is secure.
6. Differences
All the values which is submitted by the GET method will be
appended to the URL.
Where as POST method send the data with out appending the
URL(hidden)
In GET Method we can bookmark the URLs where as in POST
method its not possible
In GET Method there is a limit for passing the data from one page
to another
But in POST we can send large amount of data
Compared to POST get is Faster
POST is more secure than get method
All the informations which is passed by GET method will be stored
in webserver(log file) but in POST we can not
7. Example
Welcome.html Forms.php
<html> <html>
<body> <body>
<form action="forms.php" Welcome <?php echo
method="post"> $_POST["fname"]; ?>!<br />
Name: <input type="text" You are <?php echo
name="fname" /> $_POST["age"]; ?> years old.
Age: <input type="text" </body>
name="age" /> </html>
<input type="submit" />
</form> Output:
</body> Welcome sai!
</html> You are 15 years old.
Output: