【问题标题】:Redirects to broken url in codeigniter重定向到 codeigniter 中损坏的 url
【发布时间】:2017-07-18 22:26:27
【问题描述】:

我编写了代码来检查用户是否在数据库中拥有所有必需的信息。如果用户有,什么也不做,但如果他们是空的,则重定向到continueregistration 页面。但是当它重定向时,它会写

此页面无法正常工作

localhost 将您重定向了太多次。尝试清除您的 cookie。 ERR_TOO_MANY_REDIRECTS

我清除了我的缓存它不起作用。这是我的看法:

<?php 

    if($this->session->userdata('logged_in')) {
    $query = $this->db->get_where('instructors', array('id' => $this->session->userdata('id'))); 

    $insdatacheck = $query->row_array();

    if($insdatacheck['name'] == '') {
      redirect('/user/continueregistration/');
    } else { ?>
      <script type="text/javascript">alert('hello');</script>
      <?php
    }

    }

?>

和控制器:

function continueregistration() {

        //set validation rules
        $this->form_validation->set_rules('name', 'name', 'trim|required|alpha|min_length[2]|max_length[30]');
        $this->form_validation->set_rules('web', 'web adress', 'trim|required|valid_url|prep_url|min_length[3]');
        $this->form_validation->set_rules('facebook', 'facebook adress', 'trim|valid_url|prep_url|min_length[3]');
        $this->form_validation->set_rules('twitter', 'twitter adress', 'trim|valid_url|prep_url|min_length[3]');
        $this->form_validation->set_rules('youtube', 'youtube adress', 'trim|valid_url|prep_url|min_length[3]');
        $this->form_validation->set_rules('instagram', 'instagram adress', 'trim|valid_url|prep_url|min_length[3]');
        $this->form_validation->set_rules('tel', 'telephone number', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]');
        $this->form_validation->set_rules('address', 'address', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]');
        $this->form_validation->set_rules('insdescription', 'description', 'trim|required|alpha_numeric_spaces|min_length[3]'); 

        $data['title'] = 'Continue Registration';
        $data['instructors'] = $this->single_instructor_model->get_instructor_info();

            $this->load->view('templates/header');
            $this->load->view('registration/registration', $data);
            $this->load->view('templates/footer');

        //validate form input
        if ($this->form_validation->run() == FALSE)
        {
            // fails
            $this->load->view('templates/header');
            $this->load->view('registration/registration', $data);
            $this->load->view('templates/footer');
        }
        else
        {
            //insert the user registration details into database
            $dataforreg = array(
                'name' => $this->input->post('name'),
                'web' => $this->input->post('web'),
                'fb' => $this->input->post('facebook'),
                'twitter' => $this->input->post('twitter'),
                'youtube' => $this->input->post('youtube'),
                'instagram' => $this->input->post('instagram'),
                'phone' => $this->input->post('tel'),
                'address' => $this->input->post('address'),
                'description' => $this->input->post('insdescription')
            );

            // insert form data into database
            if ($this->user_model->updateUser($dataforreg, $to_email)) {
                    redirect('homepage/index');

            }
            else
            {
                // error
                $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Error</div>');
                    redirect('user/continueregistration');
            }
        }


    }

【问题讨论】:

  • 这意味着你有一个重定向循环
  • 您对这段代码有什么看法?它实际上应该在控制器中。尽管。视图纯粹是为了展示。任何业务逻辑或流程控制都不应该出现在视图中。
  • 你在 continueregistration 中调用 continueregistration
  • @inarilo 我在哪里称呼它?
  • @MilanMarkovic 它在 header.php 中

标签: php codeigniter redirect


【解决方案1】:

我认为您遇到了“确认重新提交表单”消息。当您的用户不可用时会发生这种情况。它指向用户/继续注册,您只需重定向而不刷新,然后它将数据发送到数据库并继续重定向。为此,您应该设置:redirect('link', 'refresh');并确认提交按钮,如果被点击,则执行里面的动作。

if(isset($_POST['submit'])         //button with the name "submit"
{
    //action
}

【讨论】:

  • 其实不是表格。这只是一个页面
猜你喜欢
  • 2012-10-04
  • 1970-01-01
  • 1970-01-01
  • 2017-04-15
  • 2012-07-07
  • 1970-01-01
  • 2017-09-16
  • 2014-04-16
  • 1970-01-01
相关资源
最近更新 更多