如何在codeigniter中检查请求是否是POST或GET请求?

时间:2014-10-31 20:29:20

标签: php codeigniter request http-post http-get

我只是想知道是否有一种非常简单的方法来确定请求是$_POST还是$_GET请求。

Codeigniter也有类似的内容吗?

$this->container->isGet();

3 个答案:

答案 0 :(得分:33)

我从未使用过codeigniter,但为此我检查了$_SERVER['REQUEST_METHOD']

the docs可能是这样的:

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

如果您要使用它,那么很简单就可以为它推出自己的isGet()函数。

答案 1 :(得分:6)

对于CodeIgniter 3用户:the docs state输入类具有获取请求方法的函数:

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

答案 2 :(得分:0)

在代码点火器4中:

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