Monday, 4 April 2016

DIFFERENCE BETWEEN GET AND POST METHOD

DIFFERENCE BETWEEN GET  AND POST METHOD



Get and Post both are used to send the data from client to server. But there are several reason that POST is more preferred choice for the security purpose. You have hear of this line many time, but have you ever questioned to yourself or try to know why POST is more secure than GET?

Let's not get panic, I will discuss it in the below section.

Remember about the query string .When you submit any form, your data transfer as a query string. For Example:

http:/myDomain/somePage.php?pin='AFADACV'&id='SADDA'

If you are making a request with GET method then all form data will be appear on the browser URL, making it insecure. Where this does not happen in case of POST method.

POST is more secure than GET method in various reasons:


  • GET requests can be cached

  • GET requests can remain in the browser history

  • GET parameters are passed via URL


This means that parameters are stored in server logs, and browser history. When using GET, it makes it very easy to alter the data being submitted the the server as well, as it is right there in the address bar to play with.

However this does not happen with POST method.

But here are some questions now. if the data appear in the URL then how it is unsafe, after all you are working in your personal computer?
If you are not working in your computer then there can be issue.



Security with GET request

Encode the data with some encoded scheme and then decode data at server side.

They both submit plain text data in the HTTP header, and base64 isn't exactly rocket science (and you can base64 encode your POST version).

When to use which method depends on your requirements. Here are some points to be noted for GET and POST.



GET 


  • The GET method can send data up-to 2048 characters only.

  • Never use GET method if you have password or other sensitive information to be sent to the server, because it can be hacked in the mid way.

  • GET can't be used to send binary data, like images or word documents, to the server. 


  • Get data deals only with the ASCII value not with the binary data.

Example

Save the below code in myfile.php and then fill the form:

<?php
   if( $_GET["firstname"] && $_GET["firstname"]) 
  {
      echo "Welcome ". $_GET['firstname']. "<br />";    
      exit();
   }
?>
<html>
   <body>
   
      <form action = "<?php $_PHP_SELF ?>" method = "GET">
         First Name: <input type = "text" name = "firstname" />
         Last Name: <input type = "text" name = "lastname" />
         <input type = "submit" />
      </form>
      
   </body>
</html>



POST


  • The POST method does not have any restriction on data size to be sent, you can sent any size of data.

  • The POST method can be used to send ASCII as well as binary data, for example images.

  • you can access the post data from $_POST['variable_name'] method


Example

Save the below code in myfile.php and then fill the form:

<?php
   if( $_POST["firstname"] && $_POST["firstname"]) {
      echo "Welcome ". $_POST['firstname']. "<br />";    
      exit();
   }
?>
<html>
   <body>
   
      <form action = "<?php $_PHP_SELF ?>" method = "GET">
         First Name: <input type = "text" name = "firstname" />
         Last Name: <input type = "text" name = "lastname" />
         <input type = "submit" />
      </form>
      
   </body>
</html>


Please open the below link which tells a lot about these two method choice and security. 


Please open the below link which tells what HTTP explained meant to these two 

No comments:

Post a Comment