Search code examples
phpcodeigniterrequesthttp-posthttp-get

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


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();

Solution

  • 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.