user815437
user815437

Reputation:

is checking $_SERVER['REQUEST_METHOD'] to determine request type bad practice?

I'm making a system that needs to be able to accept input from both get and post and process accordingly. I want to avoid $_REQUEST because some of our servers aren't configured to use it and I don't want to micromanage that. What I'd like to know is if it's bad practice to do something like this:

    switch ($_SERVER['REQUEST_METHOD']) {
        case 'POST':
            $this->_process($_POST); 
            break;
        case 'GET': 
            $this->_process($_GET);
            break;
    }

*Ignore the lack of preprocessing of post data for now

Upvotes: 0

Views: 670

Answers (1)

Niko
Niko

Reputation: 26730

Checking the method of the request is exactly what $_SERVER['REQUEST_METHOD'] is intended for. So no problem with that.

This value is actually part of the CGI specification and should therefore be provided by any decent webserver:

The REQUEST_METHOD meta-variable MUST be set to the method which should be used by the script to process the request, as described in section 4.3.

Upvotes: 3

Related Questions