1

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

  • what is the value of the $_GET variable during a POST request?
  • what is the value of the $_POST variable during a GET request?
3
  • A POST request has set $_POST values. A GET request has set $_GET values? Commented Feb 10, 2012 at 16:09
  • Does that mean the "wrong" superglobal doesn't exist? Is empty? Exists, but is equal to NULL? And what happens if you do a POST on a URL like "some.site/page?arg1=foo&arg2=bar"? Commented Feb 10, 2012 at 16:11
  • 3
    @Nanne A POST request can also have $_GET values. A GET request will not have $_POST values. Commented Feb 10, 2012 at 16:30

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

5

Use $_SERVER['REQUEST_METHOD']

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

Taken from the $_SERVER docs

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.