Home > Backend Development > PHP Problem > How to determine whether it is a get or post request in php

How to determine whether it is a get or post request in php

青灯夜游
Release: 2023-03-13 07:58:02
Original
6975 people have browsed it

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')".

How to determine whether it is a get or post request in php

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']
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template