How to receive post/get request in codeigniter

前端 未结 2 1316
梦谈多话
梦谈多话 2021-01-20 16:13

Im using

$this->input->post(\'name\') ; to get a request posted to my url.Instead of post I need to access get as well.

Like in normal ph

相关标签:
2条回答
  • 2021-01-20 16:32

    Try this if you want to post request from server

    if ($this->input->server('REQUEST_METHOD') == 'POST'){}
    
    if ($this->input->server('REQUEST_METHOD') == 'GET'){}
    
    0 讨论(0)
  • 2021-01-20 16:42

    It's outlined in the docs here: http://ellislab.com/codeigniter/user-guide/libraries/input.html

    To grab data from the get you can use

    $this->input->get('some_data', TRUE);
    

    That looks for some_data in the query string, and will run is through XSS filtering to clean it from possible hack attempts

    There's also a handy method to check both at the same time:

    $this->input->get_post('some_data', TRUE);
    

    "This function will search through both the post and get streams for data, looking first in post, and then in get"

    0 讨论(0)
提交回复
热议问题