What is the difference between Get and Post method
The $_GET variable is used to collect data from form.This variable is an array of variable names and their values that are sent by HTTP GET method.The information sent by using get method is visible to everyone in the url that is by we cannot send the secure values like password by this get method.Its also have the limit to amount of information send .
<form action="web.php" method="get"> Name: <input type="text" name="name" /> Email: <input type="text" name="email" /> <input type="submit" value="submit"/> </form>
When you submit the form ,you will goes to web.php page and your URL look like this with variables in query string name,emails etc.
You can get the value in web.php page using $_GET variable.
<?php echo $_GET["name"]; echo $_GET["email"]; ?>
The $_POST variable is used to collect information from form using POST method.This variable is an array of variable names and their values that are sent by HTTP POST method.The information is send by the post method is not visible to other and its has no limit to send data.
<form action="web.php" method="post"> Name: <input type="text" name="name" /> Email: <input type="text" name="email" /> <input type="submit" value="submit"/> </form>
When you submit the form ,you will goes to web.php page and your url look like this with not any query string.No value send in the URL.
You can get the value in web.php page using $_POST variable.Since value not send in URL so its a secure method.
<?php echo $_POST["name"]; echo $_POST["email"]; ?>
Difference between GET & POST method
(1) POST method is secure than GET method.Because the information send by POST method is not displays but nformation send by GET method is displays in the URL.
(2) The GET method is send information through URL so its have limit to send data but POST method does not have limit to send data.With GET method we can send only 255 characters.
(3) The GET method is faster than the POST method.
(4) The GET method is default method for any form but we have to set the POST method in the form.
(5) The parameter send by GET method remains in the browser history but the parameter send by POST method not saved in browser history.
(6) The GET method can be bookmarked but the post method not bookmarked.
(7) Using GET method we can send only ASCII characters but by using POST method we can send binary data also.
(8) The GET request is sent via URL string and as we all know that URL can be text-only, so GET can carry only text data but POST has no such restriction and it can carry both text as well as binary data.
(9) When we re submit data the POST method send an alert that data is sending again but the GET method not send any alert.
(10) The encoding type used in GET method is application/x-www-form-urlencoded and in POST method or multipart/form-data application/x-www-form-urlencoded .Use multipart encoding for binary data.
(11) The GET method can be cached but the POST method cannot be cached.
(12) The GET method is easier to hack but the POST method is not easier to hack.