How can I find out the method of http request by PHP? [duplicate]

2

I know that every HTTP request made, either by the browser or another resource, sends a certain method ( GET , POST , PUT , DELETE and so on).

I'm thinking of building a Restful application with PHP, but I do not know how I can do it to find out what the current request method is, so I can validate it.

If it is a GET request in a url that only accepts POST , I want to return Error 405 , which is método não aceitável .

How to know the current request method by PHP?

    
asked by anonymous 12.08.2016 / 20:10

1 answer

2

You can use the following code:

if( $_SERVER['REQUEST_METHOD'] == 'POST'){
  //retorne 405;
}
    
12.08.2016 / 20:17