GET and POST Methos in PHP

Methods of Sending Information to Server

A web browser communicates with the server typically using one of the two HTTP (Hypertext Transfer Protocol) methods — GET and POST. Both methods pass the information differently and have different advantages and disadvantages, as described below.
The GET Method

In GET method the data is sent as URL parameters that are usually strings of name and value pairs separated by ampersands (&). In general, a URL with GET data will look like this:
http://www.example.com/test.php?action=del&id=1

Advantages and Disadvantages of Using the GET Method

Data sent by the GET method are displayed in the URL, it is possible to bookmark the page with specific query string values.
The GET method is not suitable for passing sensitive information such as the username and password, because these are fully visible in the URL query string.
Because the GET method assigns data to a server environment variable, the length of the URL is limited. So, there is a limitation for the total data to be sent.

<?php

if(isset($_GET[“name”])){

echo “This GET example Name:, ” . $_GET[“name”] ;

}

?>

<form method=”get” action=”<?php echo $_SERVER[“PHP_SELF”];?>”>

<label for=”inputName”>Name:</label>

<input type=”text” name=”name”>

<input type=”submit” value=”Submit”>

</form>

The POST Method

In POST method the data is sent to the server. Data sent through POST method will not visible in the URL.
It is more secure than GET because user-entered information is never visible in the URL query string or in the server logs.
There is a much larger limit on the amount of data that can be passed and one can send text data as well as binary data (uploading a file) using POST.

PHP provide another superglobal variable $_POST to access all the information sent via post method or submitted through an HTML form using the method=”post”.

<?php

if(isset($_POST[“name”])){

echo “This post example Name:, ” . $_POST[“name”];

}

?>

<form method=”post” >

<label for=”inputName”>Name:</label>

<input type=”text” name=”name” >

<input type=”submit” value=”Submit”>

</form>

$_REQUEST
PHP provides another superglobal variable $_REQUEST that contains the values of both the $_GET and $_POST

<?php

if(isset($_REQUEST[“name”])){

echo “This post example Name:” . $_REQUEST[“name”];

}

?>

<form method=”post” >

<label for=”inputName”>Name:</label>

<input type=”text” name=”name” >

<input type=”submit” value=”Submit”>

</form>