You can use the variable "$_SERVER" in php to determine whether it is a get or post request. The syntax is "if($_SERVER['REQUEST_METHOD']==='GET')" or "if($_SERVER[' REQUEST_METHOD']==='POST')".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In actual use, GET is used to retrieve Data, such as what page to jump to, and make some logical judgments.
POST is mostly form submission. It is highly not recommended to use GET when using forms, unless as I said above, your behavior is to obtain data. GET will be easier to understand logically.
PHP is very simple. It unifies GET and POST and simply puts them into a variable. There is no need to understand the logic of the entire request. Therefore, in PHP, there is little thought about whether to use post or get.
PHP determines whether the request type is POST or GET. The correct method is
$_SERVER['REQUEST_METHOD']
A simple PHP determines whether the request type is POST or GET. Sample code:
Copy after login
Note:
$_SERVER['REQUEST_METHOD'] The value is in uppercase: GET or POST;
$_SERVER['REQUEST_METHOD'] The request type of some other values As follows:
GET is to obtain data from the server
POST is to send the data that needs to be processed to the server
HEAD Gets the header information corresponding to the GET method
PUT Updates or replaces an existing resource
DELETE Delete a server Resources on
TRACE Track the header information transmitted to the server
OPTION Obtain the http method for obtaining resources supported by the server
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether it is a get or post request in php. For more information, please follow other related articles on the PHP Chinese website!