Skip to content

Difference Between GET And POST Methods In Php?

In php, there are two methods used for the communication between a web browser and a web server namely GET and POST. Both of these perform their function by sending a set of information to the web server. Web server receives the request(a set of information) made by the client and then send the relevant information back to the browser client.

Check More details about Our Php training in Gurgaon for beginners and advanced users

The information is first converted into a code by the web browser by the URL encoding mechanism. It is also known as percent-encoding. This encoded information includes the name and value pairs which are separated by the ampersand logogram (&). For example, name=amit&age=25

Both the methods exhibits several pros and cons although Post method is widely used by the web developers in writing php scripts due to its high security level as compared to the Get method.

Before giving you the difference between Get and Post methods, let us have a look on the basic features of both the two methods.

GET METHOD

In this method, the request page and the encoded information including query strings(name=amit&age=25) is sent to the web server as the URL parameters which is visible to the user. Both the request page and the encoded information are separated by (?).

URL instance : (http://www.w3trainingschool.com/demo.php?name=amit&age=25)

In the above example, bold characters represents the GET parameters and the italic characters represents the value of GET parameters.

The superglobal variable array $_GET is used in php to fetch all the relevant information sent through the URL.

php-get

Example : We have shown below an example of Contact Form using Get Method.

php-getoutput

Output : The output of the above example of Contact Form using Get Method is shown below. Clearly, as the user entered her name(gunjan), email id(gunjan%40gmail.com), and password(abc12345) in the contact form and submitted the form, her details are visible in the URL.

POST METHOD

In this method, the request page and the encoded information is sent to the web server through a document body which is not visible in the Uniform Resource Locator(URL).

URL instance : http://www.w3trainingschool.com/demo.php

In the above example, the encoded information is hidden and is not visible to the user unlike the example shown in the GET method.

The superglobal variable array $_POST is used in this method to fetch all the relevant information.

php-post

Example : We have shown below an example of Contact Form using Post Method.

Output : The output of the above example of Contact Form using Post Method is shown below. In this case, the details including name, email id and password submitted by the user are not visible in the URL after the user has successfully signed up. Thus, making the use of Post Method more secured as compared to the Get Method.

During the php training students complete lot’s of small php based project and they properly Get and Post method. Get and post methods can be used several times and in several situations to complete php projects successfully.

php-postoutput

DIFFERENCE BETWEEN GET AND  POST METHODS

⏩ In Get method, the information entered by the user is visible in the URL while it is not visible in the Post method. Hence, making the Post method more secured than the Get method.

⏩ The URL request made using the Get method can be bookmarked while they cannot be bookmarked using the Post method.

⏩ The information in Get method can be cached while they cannot be cached in the Post method.

⏩ In Get method, the length of the data is restricted to limited characters while Post method have no restrictions on the length of the data.

⏩ The information entered by the user in the Get method remains in the browser history or logs while in the Post method information entered by the user is not saved in the browser history or logs.

⏩ Get method doesn’t send binary data(images and documents) to the web server and allows only ASCII characters while Post method can be utilized to send binary data to the web server and enables a user to upload necessary files.

⏩ Get method is not used to transfer the sensitive information as it is less secured while post method is dominantly used as it is highly secured.

Facebook
Twitter
LinkedIn
Pinterest