How to detect HTTP method in CodeIgniter How to detect HTTP method in CodeIgniter codeigniter codeigniter

How to detect HTTP method in CodeIgniter


Thanks to Branden, I've found the answer.$this->input->server($index) is identical to $_SERVER[$index].

To get method you can use: $this->input->server('REQUEST_METHOD').

UPDATE: (thanks to Ecir Hana)

As of CodeIgniter 3, using of method is also possible:

echo $this->input->method(TRUE); // Outputs: POSTecho $this->input->method(FALSE); // Outputs: postecho $this->input->method(); // Outputs: post


In CodeIgniter 3, you can use the method uhm...method of Input Class.

From the docs:

echo $this->input->method(TRUE); // Outputs: POSTecho $this->input->method(FALSE); // Outputs: postecho $this->input->method(); // Outputs: post


You can detect GET and POST by using the Input library.

$this->input->post() or $this->input->get()

More information can be found: http://ellislab.com/codeigniter%20/user-guide/libraries/input.html