Codeigniter $this->input->post() empty while $_POST is working correctly

前端 未结 13 1337
我在风中等你
我在风中等你 2020-12-05 14:56

On a codeigniter installation, I am trying to use the inbuilt $this->input->post(\'some_data\') function, however $this->input->post()

相关标签:
13条回答
  • 2020-12-05 15:15

    Use

    var_dump($this->input->post());
    

    Please see the screen shot. Here I am priniting all the post array value

    0 讨论(0)
  • 2020-12-05 15:17

    There's a few things you can look for help solve this.

    1. Has anything changed or been extended in the core CodeIgniter files. Check that system/core/Input.php is an original copy and the contents of application/library and application/core for additional files

    2. Do the other input methods work? What is the result of this when run beside your print_r call?

      echo $this->input->user_agent();

    3. What data is output from print_r? Look in application/config/config.php for the line $config['global_xss_filtering']. Is this set to TRUE or FALSE? If TRUE maybe the cross site scripting filter has a problem with the data you're posting (this is unlikely I think)

    0 讨论(0)
  • 2020-12-05 15:19

    You can check, if your view looks something like this (correct):

    <form method="post" action="/controller/submit/">
    

    vs (doesn't work):

    <form method="post" action="/controller/submit">
    

    Second one here is incorrect, because it redirects without carrying over post variables.

    Explanation:

    When url doesn't have slash in the end, it means that this points to a file.

    Now, when web server looks up the file, it sees, that this is really a directory and sends a redirect to the browser with a slash in the end.

    Browser makes new query to the new URL with slash, but doesn't post the form contents. That's where the form contents are lost.

    0 讨论(0)
  • 2020-12-05 15:19

    You are missing the parent constructor. When your controller is loaded you must Call the parent CI_Controller class constructor in your controller constructor

    0 讨论(0)
  • 2020-12-05 15:19

    The problem is that $this->input->post() does not support getting all POST data, only specific data, for example $this->input->post('my_post_var'). This is why var_dump($this->input->post()); is empty.

    A few solutions, stick to $_POST for retrieving all POST data, or assign variables from each POST item that you need, for example:

    // variables will be false if not post data exists
    $var_1 = $this->input->post('my_post_var_1');
    $var_2 = $this->input->post('my_post_var_2');
    $var_3 = $this->input->post('my_post_var_3');
    

    However, since the above code is not very DRY, I like to do the following:

    if(!empty($_POST)) 
    {
        // get all post data in one nice array
        foreach ($_POST as $key => $value) 
        {
            $insert[$key] = $value;
        }
    }
    else
    {
        // user hasen't submitted anything yet!
    }
    
    0 讨论(0)
  • 2020-12-05 15:20

    Try This, change

    $config['base_url'] = 'http://mywebsite.cl/';
    

    to

    $config['base_url'] = 'http://www.mywebsite.cl/';
    

    Some provider auto add www , https , etc to your url, most of the times, this causes this issue

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