How can I check if request was a POST or GET request in codeigniter? How can I check if request was a POST or GET request in codeigniter? codeigniter codeigniter

How can I check if request was a POST or GET request in codeigniter?


I've never used codeigniter, but for this I check the $_SERVER['REQUEST_METHOD'].

Looking at the docs maybe something like:

if ($this->input->server('REQUEST_METHOD') === 'GET') {   //its a get} elseif ($this->input->server('REQUEST_METHOD') === 'POST') }   //its a post}

If you're going to use it a lot then it's simple to roll your own isGet() function for it.


For CodeIgniter 3 users: the docs state the input class has a function to get the request method:

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


In codeigniter 4:

$this->request->getMethod() // Returns get, post, or whatever the method is