Difference Between Get and Post Method in PHP ?



Difference Between Get and Post Method in PHP ?

$_GET Method $_POST Method
GET requests can be cached. POST requests are never cached.
GET requests remain in the browser history. POST requests do not remain in the browser history.
Easier to hack for script kiddies. More difficult to hack.
Restrictions on form data type. Only ASCII characters
allowed.
No restrictions. Binary data is also allowed.
GET requests can be bookmarked. POST requests cannot be bookmarked.
GET is less secure compared to POST because data sent
is part of the URL. So it's saved in browser history
and server logs in plaintext.
POST is a little safer than GET because the parameters are not stored in browser history or in web server logs.
GET requests have length limitations. POST requests have no limitations on data length .
GET method should not be used when
sending passwords or other sensitive data.
GET requests is only used to request data (not modify).
POST method used when sending passwords or other sensitive data.

Sample Code

<!DOCTYPE html> 
<html lang="en"> 
<head>
 <title>Example of PHP GET method</title> 
</head> 
<body> 
<?php
 if(isset($_GET["name"])){
 echo "<p>Hi, " . $_GET["name"] . "</p>"; 
} ?>
 <form method="get" action="<?
php echo $_SERVER["PHP_SELF"];?>"> <label for="inputName">Name:</label> <input type="text" name="name" id="inputName"> <input type="submit" value="Submit"> </form> </body>

Sample Code

<!DOCTYPE html> 
<html lang="en">
 <head> 
<title>Example of PHP POST method</title>
 </head> <body> 
<?php 
if(isset($_POST["name"])){ 
echo "<p>Hi, " . $_POST["name"] . "</p>"; } 
?> 
<form method="post" action="
<?php echo $_SERVER["PHP_SELF"];? >"> <label for="inputName">Name:</label> <input type="text" name="name" id="inputName"> <input type="submit" value="Submit"> </form> </body>

Related Searches to Get and Post Method ?