B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP PHP GET and POST Tutorial | LiveCodeProgramming

PHP GET and POST

PHP uses $_GET and $_POST to collect form data submitted through HTML forms. $_GET appends data to the URL while $_POST sends data in the HTTP request body.

PHP $_GET और $_POST का उपयोग HTML forms के माध्यम से भेजे गए डेटा को प्राप्त करने के लिए किया जाता है। $_GET डेटा को URL में जोड़ता है जबकि $_POST डेटा को request body में भेजता है।

Live Demo: GET Method

Name:

Live Demo: POST Method

Name:

Code Example: $_GET

<form method="get" action="">
  Name: <input type="text" name="username">
  <input type="submit" value="Submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "GET") {
  echo $_GET['username'];
}
?>
(Output will show entered username from URL query string)

Code Example: $_POST

<form method="post" action="">
  Name: <input type="text" name="username">
  <input type="submit" value="Submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  echo $_POST['username'];
}
?>
(Output will show entered username after form submit)

Comparison Table: GET vs POST

Aspect GET POST
VisibilityVisible in URLHidden in request body
SecurityLess secureMore secure
UsageSearch, filterLogin, forms
Data LengthLimitedUnlimited
BookmarkableYesNo