While dealing with forms and data, there are HTTP methods that help in collecting and sending of data. These methods help between the interaction of server and client through the transfer of data. Such methods include two different request methods, GET and POST.

HTTP protocol supports various methods that are involved for manipulation with data and are encoded before the data is sent, using the URL encoding scheme. The POST method supplies information from client to server in the message body whereas the GET method includes all the required data in the URL. After it’s encoded, the information is then transferred to the server. In this article we’ll discuss the difference between GET and POST and how they’re used, but before that let’s understand the concept of each individually.

What is GET Method?

The GET method is used for fetching the data entered by the user but it has a drawback that it appends the input of the user into the URL, where the length of the URL is limited. The method is commonly used for submission of forms so that users can bookmark the result or for sending data that’s not secure. You can not send password or sensitive information through this method.

Furthermore, you can not use this method for sending images or word documents that are in binary data form. To access the sent information the syntax $_GET is used which is an associative array.

Example:

<?php

  if( $_GET[“name”] || $_GET[“city”] ) {

     echo “Welcome “. $_GET[‘name’].
“;

      echo “Your city is: “. $_GET[‘city’]. “.”;


     

   }

?>

<html>

<body>

<form action=” method=”GET”>

Name: <input type=“text” name=“name”><br>

City: <input type=“text” name=“city”><br>

<input type=“submit”>

</form>

</body>

</html>

Output:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/1-27.jpg" data-lazy- height="80" src="data:image/svg xml,” width=”319″>

After submit the URL looks like this:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/2-26.jpg" data-lazy- height="49" src="data:image/svg xml,” width=”488″>

What is POST Method?

The POST method appends the data of the form to the body of HTTP in a way that the data is not shown in the URL and there’s no limit on the size of the data that is to be sent. This method is mainly used for sending binary data and submitting secure information like password as the method goes through HTTP header, hence security depends on HTTP protocol. Hence, this method is more secure than the GET method and the data that is sent can be accessed through $_POST.

Example:

<?php

   if( $_GET[“name”] || $_GET[“password”] ) {

      echo “Welcome “. $_GET[‘name’].
;

     


     


   }

?>

<html>

<body>

<form action=“” method=“POST”>

Name: <input type=“text” name=“name”><br>

Password: <input type=“text” name=“password”><br>

<input type=“submit”>

</form>

</body>

</html>

Output:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/3-26.jpg" data-lazy- height="67" src="data:image/svg xml,” width=”304″>

After submitting the URL looks like this:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/4-24.jpg" data-lazy- height="49" src="data:image/svg xml,” width=”434″>

What’s the Difference between GET and POST?

As we explained the both methods separately, we saw that the GET methods parameters are displayed in the URL, whereas for POST methods the parameters were not present in the URL. This shows how secure the POST method is and while submitting important information, it’s always best to use the POST method instead of the GET method.

Furthermore, the GET method is mostly used for fetching the data whereas, POST is used to manipulate the data that is stored in the server. The POST method can send unlimited data whereas for the GET method there’s a particular limit that is 2048 characters and it’s cacheable whereas POST is not cacheable.

Conclusion

HTTP methods are used for dealing with data, sending and receiving data and manipulation. There are two particular methods used for HTTP requests: GET and POST, which differ from each other in various ways. In this article we discussed each method separately and then discussed how they differ from each other.

Mostly to send secure data we use the POST method as it does not show the parameters passed in the URL, hence proving to be safer security-wise. We discussed further how one of them comes with a limit on data being sent. I hope now you’ve a better understanding of which method to use.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/7011409B3A384F43A8417D1DAC68D179-150×150.jpg6164f878bb852.jpg" height="112" src="data:image/svg xml,” width=”112″>

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.