PHP Form Handling

The $GET and $POST superglobals in PHP are used to gather form-data. The request for the form can be received or uploaded. We need to use $GET to retrieve data from get request, $POST for post request.

1) $_GET

The GET method sends encoded user information attached to the request for a page.
On the URL client the data passed through get request is available so it is not protected.

<form method=”get” action = “ ”> 
<input type="text" name="email">

In the URL the information sent through the $GET method is available. For example, if you enter in the form above an email from [email protected] and send the address, this is how URL will look at the localhost:


2) $_POST

The system POST transmits information through HTTP headers.

ASCII as well as binary data can be submitted using the POST process.

Post request is commonly used to send form which has large amounts of data such as uploading images, uploading files, login form, registration form etc.

    // collect value of input field
    $name = $_POST['name'];
    if (empty($name)) {
        echo "Name is empty";
    } else {
        echo $name;

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="name">
  <input type="submit">

Diffrence between $_GET and $_POST Methods