错误310(net :: ERR_TOO_MANY_REDIRECTS)

时间:2011-08-09 18:38:25

标签: php codeigniter redirect

为什么在codeigniter中使用重定向后我有这个错误:

  

错误310(net :: ERR_TOO_MANY_REDIRECTS):太多了   重定向。

如果使用此:redirect('admin/hotel/insert', 'refresh');,刷新页面不停,爆发 我该怎么办?

控制器function中的代码(hotel):

function insert(){
    $this->load->view('admin/hotel_submit_insert');
        $today = jgmdate("j F Y");
        $data = array (
        'name' => $this->input->post('name', TRUE),
        'star' => $this->input->post('star', TRUE),
        'address' => $this->input->post('address', TRUE),
        'number_phone' => $this->input->post('number_phone', TRUE),
        'fax' => $this->input->post('fax', TRUE),
        'site' => $this->input->post('site', TRUE),
        'email' => $this->input->post('email', TRUE),
        'useradmin' => $this->input->post('useradmin', TRUE),
        'date' => $today ,
        );
        $this->db->insert('hotel_submits', $data);
        redirect('admin/hotel/insert'); // after use of this
    }

尊重

2 个答案:

答案 0 :(得分:0)

尝试这样做......

function insert(){

    // If you are posting data, do the insert
    if ($_POST)
    {
        $today = jgmdate("j F Y");
        $data = array (
            'name' => $this->input->post('name', TRUE),
            'star' => $this->input->post('star', TRUE),
            'address' => $this->input->post('address', TRUE),
            'number_phone' => $this->input->post('number_phone', TRUE),
            'fax' => $this->input->post('fax', TRUE),
            'site' => $this->input->post('site', TRUE),
            'email' => $this->input->post('email', TRUE),
            'useradmin' => $this->input->post('useradmin', TRUE),
            'date' => $today ,
        );
        $this->db->insert('hotel_submits', $data);
    }

    // then load the view no matter what
    $this->load->view('admin/hotel_submit_insert');
}

答案 1 :(得分:-3)

好的,所以你需要确保插入只发生一次。

因此,您需要在运行重定向之前检查发布数据是否可用。这里发生的是代码不断插入数据和重定向页面。

function insert(){

// If you are posting data do the insert
if (isset($this->input->post('name')) && strlen($this->input->post('name')) //just double checking.
{
    $today = jgmdate("j F Y");
    $data = array (
        'name' => $this->input->post('name', TRUE),
        'star' => $this->input->post('star', TRUE),
        'address' => $this->input->post('address', TRUE),
        'number_phone' => $this->input->post('number_phone', TRUE),
        'fax' => $this->input->post('fax', TRUE),
        'site' => $this->input->post('site', TRUE),
        'email' => $this->input->post('email', TRUE),
        'useradmin' => $this->input->post('useradmin', TRUE),
        'date' => $today ,
    );
    if($this->db->insert('hotel_submits', $data))
        redirect('admin/hotel/insert');
}

//And load the view
$this->load->view('admin/hotel_submit_insert');

}