【问题标题】:Codeigniter redirect not working in websiteCodeigniter 重定向在网站中不起作用
【发布时间】:2016-07-31 10:46:22
【问题描述】:

我在我的一种方法中遇到了无法正常工作的重定向。但其余的重定向正在工作。 顺便说一句,在我的本地主机中,重定向正在工作,但是当我把它放在我的站点中进行测试时。它没有传递到该重定向,而是停留在 signup_validation 中,并且仍然在我的电子邮件中收到电子邮件验证。

public function signup_validation() {

    $account = array(
        'email' => strip_tags($this->input->post('email')),
        'password' => sha1($this->input->post('password')),
        'firstname' => strip_tags($this->input->post('firstname')),

        'lastname' => strip_tags($this->input->post('lastname')),
        'contact_number' => $this->input->post('contact_number'),
        'home_address' => strip_tags($this->input->post('home_address')),

        'gender' => $this->input->post('gender'),

        'g-recaptcha-response' => $this->input->post('g-recaptcha-response')
    );

    $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[account.email]');
    $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[32]');
    $this->form_validation->set_rules('cpassword', 'Confirm Password', 'required|matches[password]');
    $this->form_validation->set_rules('firstname', 'First name', 'required|callback_alpha_dash_space');
    $this->form_validation->set_rules('lastname', 'Last name', 'required|callback_alpha_dash_space');
    $this->form_validation->set_rules('contact_number', 'Contact Number', 'required|callback_number|min_length[7]|max_length[11]');
    $this->form_validation->set_rules('gender', 'Gender', 'required');
    $this->form_validation->set_rules('home_address', 'required|callback_address');
    $this->form_validation->set_rules('tac', 'Terms and Condition', 'required');
    $this->form_validation->set_rules('g-recaptcha-response', 'Recaptcha', 'required');

    $this->form_validation->set_message('number', 'The %s must be a number');
    $this->form_validation->set_message('address','The %s must contain only letters, period, comma, spaces and dash.');
    $this->form_validation->set_message('is_unique', 'Email address is already used.');
    $this->form_validation->set_message('alpha_dash_space','The %s must contain only letters, period, spaces, and dash.');

    if ($this->form_validation->run() == FALSE) {
        $this->register();
    } else {
        $recaptcha = $this->input->post('g-recaptcha-response');
            if (!empty($recaptcha)) {
                $response = $this->recaptcha->verifyResponse($recaptcha);
                if (isset($response['success']) and $response['success'] === true) {
                   $this->MainModel->add_account();
                    redirect('main/email_sent', 'refresh');     
                }
            }

    }
}

【问题讨论】:

    标签: php codeigniter redirect


    【解决方案1】:

    去掉redirect()的第二个参数,当第二个参数设置为'refresh'时,这个方法只会刷新当前页面。

    redirect('main/email_sent');
    

    【讨论】:

    • 我也试过了,当我按下注册按钮时,它会存入 base_url().'main/signup_validation' 并且它不会进行重定向。以及当我在本地工作时重定向工作。
    • @EdgarOng try to echo uri you pass and die the script after echo in definition of redirect ,看看打印的url是不是你传入的。
    【解决方案2】:

    中移除第二个参数('refresh')
    redirect('main/email_sent', 'refresh'); 
    

    很高兴知道它是否有效。

    【讨论】:

    • 前段时间也说了,可惜还是没用。
    猜你喜欢
    • 2018-10-04
    • 2018-01-30
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多