Get Post and Request Method in PHP. A Php program to execute the request and post method. In this program, we can execute the request and post-program in php. $_REQUEST is a global variable in PHP that is used to collect data after an HTML form has been submitted. The example below shows a form with an input field and a submit button. When a user submits form data by clicking “Submit,” the data is transferred to the file specified in the form> tag’s action element.
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
if ($_SERVER["REQUEST_METHOD"] == "POST")
$name = $_REQUEST['fname'];
echo "File is empty";
Post Method in Php
To submit form data to the server, the HTTP request methods Get and Post are utilised within the form> element. The HTTP protocol permits communication between the client and the server, with the client being a browser and the server being an application running on a computer system that hosts your website. POST is a request method offered by HTTP that is used by the World Wide Web. The POST request method, by definition, requests that a web server accept the data included in the body of the request message, most often for storage. The HTTP GET request method, on the other hand, receives information from the server.
Form Method in Php
The PHP form action attribute determines where the data is directed for processing. The superglobals $_POST and $_GET are required to collect data from PHP forms. The GET technique is used for non-sensitive data and allows for bookmarking of pages. The POST method is used for sensitive data since it is more secure.