PHP GET and POST methods

Post date:

Author:

Category:

There are two ways the client (web browser) can send HTTP request to the web server.

  • The GET method
  • The POST method

The Hypertext Transfer Protocol (HTTP) is the medium to send GET and POST request to the web server. The Web Server processes the request.

The GET Method

The GET method sends request in encoded string. Requested information is separated by question mark (?) sign and all information is separated by Ampersand (&) sign.

http://website.com/index.php?value=1&name=1&value=2&name=2

Notes on GET method:

  • GET method requests are cached by browser
  • GET method requests always stored in browser history
  • User can bookmark GET request
  • Never use GET method when dealing with sensitive and confidential data
  • GET method is restricted to send limited data

Example:

<?php
    if(!empty($_GET["name"]))
    {
        echo "Welcome ". $_GET['name'];
        die();
    }
?>

<html>
<body>
    <form action="<?php $_PHP_SELF ?>" method="GET">
    Name: <input type="text" name="name" />
    <input type="submit" />
    </form>
</body>
</html>

The POST Method

The POST method is secure method. The POST method send request via HTTP headers

POST index.php HTTP/1.1
Host: website.com
value=1&name=1&value=2&name=2

Notes on POST method:

  • POST method requests are not cached by browser
  • POST method requests are not stored in browser’s history
  • User can bookmark POST method requests
  • Never use GET method when dealing with sensitive and confidential data
  • POST method haven’t restrictions on length of data
  • POST method is secured to send sensitive data

Example:

<?php
    if(!empty($_POST["name"]))
    {
        echo "Welcome ". $_POST['name'];
        die();
    }
?>

<html>
<body>
    <form action="<?php $_PHP_SELF ?>" method="POST">
    Name: <input type="text" name="name" />
   <input type="submit" />
   </form>
</body>
</html>

Facebook Comments

STAY CONNECTED

12,117FansLike
408FollowersFollow
973FollowersFollow
6,749SubscribersSubscribe

INSTAGRAM

Ranveer Singh and Deepika Padukone wedding date confirmed

  Sooo. After Priyanka Chopra and Nick Jonas exchanged rings, another big wedding news pop up here. According to the reports, two Sensations of B...

Ananya Pandey Became New Sensation

Bollywood Actresses   Ananya Pandey is a star kid of Bollywood, daughter of very famous comedian actor CHUNKY PANDEY. Ananya is going to launch with big...

Gold First Day Collection

Again Akki got his 6th consecutive hit as GOLD. A long awaited film did its mind blowing  performance. 27 crores crossed by Akshay Kumar’s...