There are two ways you can send forms from the client to the server: GET
and POST
. They are defined in RFC 2616 (HTTP), but the difference you can directly see is that GET
gets displayed in the URL and POST
doesn't.
Keep in mind that this is only for the browser on the client side to decide which way they send content to the server.
Regarding $_SERVER['REQUEST_METHOD']
:
Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
Note: PHP script is terminated after sending headers (it means after producing any output without output buffering) if the request method was HEAD.
One reason why you might want to use
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
might be to check if a form was submitted. But keep in mind: People can send POST
requests without actually using your form! So you have to check the other data anyway.