Check whether a request is GET or POST

Php

Php Problem Overview


> Possible Duplicate:
> PHP detecting request type (GET, POST, PUT or DELETE)

This should be an easy one.

I have a script, and in the script I want to determine whether the request arrive via GET or POST method.

What is the correct way to do it?

I am thinking of using something like this

if (isset($_POST)) {
	// do post
} else  {
	// do get
}

But deep in my heart I don't feel this is the right way. Any idea?

Php Solutions


Solution 1 - Php

Better use $_SERVER['REQUEST_METHOD']:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // …
}

Solution 2 - Php

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGravitonView Question on Stackoverflow
Solution 1 - PhpGumboView Answer on Stackoverflow
Solution 2 - PhpKV PrajapatiView Answer on Stackoverflow