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 web server. Here we will learn about these methods and 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 the GET method you can easily see all GET parameters in the URL bar like this http://www.example.com/search.php?product=books. Here we will learn how we can send data from an HTML form to a 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 the POST method data send to the web server separately as a package with a 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>

 

Spread the love
Scroll to Top
×