PHP Get and Post Method
Get method : The GET method sends the data as part of the URL, which means that the data is visible in the address bar of the browser. This method is useful for sending small amounts of data, such as search queries.
In the following HTML code we have created a form with text field as Username and Phone Number. we have also included a PHP file getmethod.php where our data would be sent after we click the submit button.
index.html
In the following PHP code using the GET method we have displayed the Username and Phone Number.
getmethod.php
Welcome
Your Phone nummber is:
Output: Data passed in GET method is clearly visible in the address bar, which can compromise the security.
Post method : The POST method sends the data in the HTTP request body, which means that it is not visible in the address bar. This method is useful for sending large amounts of data, such as form submissions.
In the following HTML code we have created a form with text field as Username and Phone Number. we have also included a PHP file postmethod.php, where our data would be sent after we click the submit button.
index.html
In the following PHP code using the POST method we have displayed the Username and Phone.
postmethod.php
Welcome
Your Phone number is:
Output: Data passed in POST method is not shown in the address bar, which maintains the security.