Difference Between Http Post & Get Methods
Http Post and Get methods are a part of the HTML language. Both methods are used in HTML form to transmit user’s data to server side programming languages such as Php, Asp.net, Jsp etc. The following difference can be found between these two methods:
Http Post Method | Http Get Method |
---|---|
Large data can be send to server (unlimited characters). | Minimal data can be send to server (only 2048 characters are allowed). |
Information can not be bookmarked in a browser. | Information can be bookmarked in a browser. |
Information is not visible in browser’s URL. | Information is visible in browser’s URL. |
Personal and secure information can be sent. | Don’t send Personal and secure information. |
Any secure information can not be hacked. | Any secure information can be hacked easily. |
Mostly is used with HTML forms (recommended). | Mostly is used with HTML hyperlinks to pass data between difference pages (recommended). |
Information can not be cached. | Information can be cached. |
Example: PHP Http Post Method
<!Doctypes html> <html> <head> <title>PHP Http Post Method</title> </head> <body> <?php if(isset($_POST['btn_submit'])) { $user_name = $_POST['user_name']; $contact = $_POST['contact']; echo "Name is: " . $user_name . "<br>"; echo "Contact: " . $contact; } ?> <form method="post" action=""> <input type="text" name="user_name" placeholder = "Enter Name"> <br><br> <input type="text" name="contact" placeholder = "Enter Contact"> <br> <button type="submit" name="btn_submit"> Submit </button> </form> </body> </html>
Example: PHP Http Get Method
<!Doctypes html> <html> <head> <title>PHP Http Get Method</title> </head> <body> <?php if(isset($_GET['btn_submit'])) { $user_name = $_GET['user_name']; $contact = $_GET['contact']; echo "Name is: " . $user_name . "<br>"; echo "Contact: " . $contact; } ?> <form method="get" action=""> <input type="text" name="user_name" placeholder = "Enter Name"> <br><br> <input type="text" name="contact" placeholder = "Enter Contact"> <br> <button type="submit" name="btn_submit"> Submit </button> </form> </body> </html>