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

uubf1zoe  于 2022-12-07  发布在  其他
关注(0)|答案(4)|浏览(163)

我只是想知道是否有一种非常简单的方法来确定请求是$_POST还是$_GET请求。
那么Codeigniter有这样的东西吗?

$this->container->isGet();
aemubtdh

aemubtdh1#

我从来没有使用过codeigniter,但对于这个,我检查了$_SERVER['REQUEST_METHOD']
看一下the docs,可能类似于:

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

如果你要经常使用它,那么为它滚动你自己的isGet()函数是很简单的。

a5g8bdjr

a5g8bdjr2#

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

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

sycxhyv73#

在代码点火器4中:

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

cigdeys34#

正确答案是:

if ($this->input->post()) {
   //have post
}

相关问题