GET and POST Method In PHP (GET vs POST)

Hey there, ITSOURCECODER’S! In this tutorial, we will learn about GET and POST Method In PHP and their Differences, which we can understand with the help of examples.

What is GET and POST Method In PHP?

The GET and POST Method in PHP are the methods through which a client or a user can send information to the server.

GET and POST Methods are the HTTP request methods used inside the <form> tag to send the different values from the form to the server.

HTTP is the protocol that enables the communication between the client and the server, where a browser can be the client, and an application running on a computer system that hosts your website can be the server.

What is Difference Between GET and POST Method In PHP?

The difference Between GET and POST method in PHP is GET method sends the information by appending them to the page request, while POST method sends information via HTTP header.

PHP is a server-side scripting language designed for web development. The GET and POST methods are two ways for a client computer to send information to the web server. These methods help to retrieve information from users by forms.

Compare GET vs POST Method in PHP

BACK button/ReloadHarmlessData will be re-submitted (the browser should alert the user that the data are about to be re-submitted)
BookmarkedCan be bookmarkedCannot be bookmarked
CachedCan be cachedNot cached
Encoding typeapplication/x-www-form-urlencodedapplication/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data
HistoryParameters remain in browser historyParameters are not saved in browser history
Restrictions on data lengthYes, when sending data, the GET method adds the data to the URL; and the length of a URL is limited (maximum URL length is 2048 characters)No restrictions
Restrictions on data typeOnly ASCII characters allowedNo restrictions. Binary data is also allowed
SecurityGET is less secure compared to POST because data sent is part of the URL

Never use GET when sending passwords or other sensitive information!
POST is a little safer than GET because the parameters are not stored in browser history or in web server logs
VisibilityData is visible to everyone in the URLData is not displayed in the URL
GET vs POST Method in PHP

GET Method

The GET Method is a PHP super global variable “$_GET“, which is used to collect data from the form after submitting an HTML form with method=”GET”.

GET can also collect data sent in the URL.

Example Program of GET Method:


<a href="get.php?subject=PHP&">Test GET</a>


When a user clicks the “Test GET” link, the parameters “subject” and “web” are sent to “get.php” file. And then a user can access their values in “get.php” file with “GET” Method.

The example below shows the code in “get.php” file:


echo "Study " . $_GET['subject'] . " at " . $_GET['web'];


When you execute the program, this will be the output:

Study PHP at

POST Method

In the POST method, the data from HTML form is submitted/collected using a super global variable “$_POST“. This method sends the encoded data from the “form” tag.

Example program of POST Method:

<!DOCTYPE html>

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

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


When you execute the program this will be the output:

POST Method No Action
POST Method No Action

When you click the “submit” button, this will be the result:

POST Method Output
POST Method Output


We have completely discussed what is PHP GET and POST Method and their difference. Also, we provide an example program for the two methods.

I hope this simple tutorial will help you a lot to comply with your requirements in PHP Programming.


By the way, If you have any questions or suggestions about this tutorial, Please feel free to comment below. Thank You!

Leave a Comment