Adrian Ratnapala
Adrian Ratnapala

Reputation: 5673

Distinguish GET from POST in PHP

I'm making a website, and have configured my web server to route any request for dynamic content to index.php. On this site, some requests are GET others are POST. How can I distinguish them? Related questions are

Upvotes: 1

Views: 684

Answers (3)

ceejayoz
ceejayoz

Reputation: 180004

what is the value of the $_GET variable during a POST request?

Depends. Data can be present in both. The action for a <form> might be example.php?action=testing, which would result in $_GET['action'] having the value of testing. All of the $_POST data would also be present.

what is the value of the $_POST variable during a GET request?

An empty array.

Upvotes: 6

Esailija
Esailija

Reputation: 140210

$_SERVER['REQUEST_METHOD'] === 'POST'

Upvotes: 4

Manse
Manse

Reputation: 38147

Use $_SERVER['REQUEST_METHOD']

Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.

Taken from the $_SERVER docs

Upvotes: 5

Related Questions