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

hecontreraso picture hecontreraso · Oct 31, 2014 · Viewed 39.2k times · Source

I just wondered if there is a very easy way to determine whether the request is a $_POST or a $_GET request.

So does Codeigniter have something like this?

$this->container->isGet();

Answer

cOle2 picture cOle2 · Oct 31, 2014

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.