HTTP GET
The Hypertext Transfer Protocol(HTTP) Get method is mainly used on the client (Browser) side to send a request to a specified server to get certain data or resources. Using this method the server should only let us receive the data and not change its state. Hence it is only used to view something and not to change it. The Get method is one of the most used HTTP methods. The request parameter of the get method is appended to the URL. Get request is better for the data which does not need to be secure (It means the data which does not contain images or Word documents).
Example: In the following HTML code we have created a form with text fields such as Username and City. we have also included a PHP file getmethod.php where our data would be sent after we click the submit button.
<!DOCTYPE html>
<html>
<body>
<form action="getmethod.php" method="GET">
Username:
<input type="text" name="username" /> <br>
City:
<input type="text" name="city" /> <br>
<input type="submit" />
</form>
</body>
</html>
In the following PHP code using the GET method we have displayed the Username and city.
<!DOCTYPE html>
<html>
<body>
Welcome
<?php echo $_GET["username"]; ?> </br>
Your City is:
<?php echo $_GET["city"]; ?>
</body>
</html>
Output: Data passed in GET method is clearly visible in the address bar, which can compromise the security.
Difference between HTTP GET and POST Methods
HTTP (Hypertext Transfer Protocol) specifies a collection of request methods to specify what action is to be performed on a particular resource. The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. This article covers the 2 most common HTTP request methods, i.e. the GET & POST Methods among the rest of the methods.
Table of Content
- HTTP GET
- HTTP POST
- Difference between HTTP GET and HTTP POST