GET and POST in PHP

By | April 6, 2020

In this tutorial, we will learn about Get and POST in PHP. The web browser communicates with the web server by using two Http methods GET and POST. These methods are used to send information to the webserver. Here we will learn about these methods and we will learn what is the difference between these two methods.

GET method:

When we use the GET method it sends data to the web server as URL parameters. It sends data to a web server in the key-value pair. When you work with GET method you can easily see all GET parameters in URL bar like this http://www.example.com/search.php?product=books. Here we will learn how we can send data from HTML form to server using the GET method.

Example Program:

<?php
if(isset($_GET["Submit"])){
    echo "<p-->Hello, " . $_GET["name"] . "<p></p>";
}
?>
<form method="GET">
    <input type="text" name="name">
    <input="" value="Submit">
</form>

POST method:

When we send data using the POST method to the webserver. Data would not visible in the URL bar. In POST method data send to web server separately as a package with processing script. Check this example to understand it.

Example Program:

<?php
if(isset($_POST["Submit"])){
    echo "<p-->Hello, " . $_POST["name"] . "<p></p>";
}
?>
<form method="POST">
    <input type="text" name="name">
    <input="" value="Submit">
</form>