Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting request type in PHP (GET, POST, PUT or DELETE)

Tags:

http

php

request

How can I detect which request type was used (GET, POST, PUT or DELETE) in PHP?

like image 729
UnkwnTech Avatar asked Dec 11 '08 11:12

UnkwnTech


People also ask

What is the difference between GET and request in PHP?

Now, There are total three super global variables to catch this data in PHP. $_POST : It can catch the data which is sent using POST method. $_GET : It can catch the data which is sent using GET method. $_REQUEST : It can catch the data which is sent using both POST & GET methods.

Are PHP methods Post?

PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post".

What is $_ request in PHP?

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.


1 Answers

By using

$_SERVER['REQUEST_METHOD'] 

Example

if ($_SERVER['REQUEST_METHOD'] === 'POST') {      // The request is using the POST method } 

For more details please see the documentation for the $_SERVER variable.

like image 140
gnud Avatar answered Oct 15 '22 13:10

gnud