Can someone explain me the difference between $_GET and $_POST

Asked 03 Dec, 15 at 05:55 PM

Mukesh Thakur

Answer

Hi Mukesh Thakur,



Kindly Go Through The Following, It Will Solve Your Issues :



The HTTP GET And POST Methods Are Used To Send Information To Server.


Methods Of Sending Information To Server


A Web Browser Communicates With The Server Typically Using One Of The Two HTTP (Hypertext Transfer Protocol) Methods — GET And POST. Both Methods Pass The Information Differently And Have Different Advantages And Disadvantages, As Described Below.


The GET Method


In GET Method The Data Is Sent As URL Parameters That Are Usually Strings Of Name And Value Pairs Separated By Ampersands (&). In General, A URL With GET Data Will Look Like This:

http://www.example.com/action.php?name=john&age=24


The Bold Parts In The URL Are The GET Parameters And The Italic Parts Are The Value Of Those Parameters. More Than One Parameter=value Can Be Embedded In The URL By Concatenating With Ampersands (&). One Can Only Send Simple Text Data Via GET Method.


Advantages And Disadvantages Of Using The GET Method


.Since The Data Sent By The GET Method Are Displayed In The URL, It Is Possible To Bookmark The Page With Specific Query String Values.

.The GET Method Is Not Suitable For Passing Sensitive Information Such As The Username And Password, Because These Are Fully Visible In The URL Query String As Well As Potentially Stored In The Client Browser's Memory As A Visited Page.
.Because The GET Method Assigns Data To A Server Environment Variable, The Length Of The URL Is Limited. So, There Is A Limitation For The Total Data To Be Sent.

PHP Provides The Superglobal Variable $_GET To Access All The Information Sent Either Through The URL Or Submitted Through An HTML Form Using The Method="get".

Example :



Example Of PHP GET Method<?php



Hi, " . $_GET["name"] . "

";
}
?>
">

Input Type="text" Name="name" Id="inputName">
Input Type="submit" Value="Submit">



The POST Method


In POST Method The Data Is Sent To The Server As A Package In A Separate Communication With The Processing Script. Data Sent Through POST Method Will Not Visible In The URL.


Advantages And Disadvantages Of Using The POST Method


.It Is More Secure Than GET Because User-entered Information Is Never Visible In The URL Query String Or In The Server Logs.
.There Is A Much Larger Limit On The Amount Of Data That Can Be Passed And One Can Send Text Data As Well As Binary Data (uploading A File) Using POST.

.Since The Data Sent By The POST Method Is Not Visible In The URL, So It Is Not Possible To Bookmark The Page With Specific Query.

Like $_GET, PHP Provide Another Superglobal Variable $_POST To Access All The Information Sent Via Post Method Or Submitted Through An HTML Form Using The Method="post".

Example :



Example Of PHP POST Method<?php



Hi, " . $_POST["name"] . "

";
}
?>
">


Input Type="text" Name="name" Id="inputName">
Input Type="submit" Value="Submit">

like