为什么页面加载这么长?

时间:2018-06-07 08:38:05

标签: php mysql codeigniter-3

当用户填写表单并单击“提交”按钮时,我正在创建注册页面。下一页的加载时间很长,有时甚至会出现错误:“CodeIgniter中超过30秒的最大执行时间”。 “CodeIgniter”电子邮件库需要这么长时间吗?还是我写错了代码?

控制器:

class Register extends CI_Controller {

public function index()
{
    $profile['first_name']  = $this->input->post('first_name');
    $profile['last_name']   = $this->input->post('last_name');
    $account['email']       = $this->input->post('email');
    $account['password']    = password_hash($this->input->post('password'), PASSWORD_DEFAULT);
    $account['permissions'] = '2';
    $account['code']        = bin2hex(random_bytes(2));
    $data['recaptcha']      = $this->recaptcha->create_box();
    $data['error']           = NULL;

    if ($this->session->userdata('logged_in') != NULL) {
        redirect('dashboard');
    }

    if($this->input->post('action') === 'submit') {
        $is_valid = $this->recaptcha->is_valid();

        if($is_valid['success']) {
            $email = $account['email'];
            $result = $this->Register_model->auth($email);
            if ($result == 0) {
                $id = $this->Register_model->insert_account($account);
                $profile['id_account'] = $id;
                $this->Register_model->insert_profile($profile);

                $newdata = array(
                    'first_name' => $profile['first_name'],
                    'email'      => $email,
                    'code'       => $account['code']
                );

                $this->email->set_newline("\r\n");
                $this->email->from('example@email.com', 'Example Email');
                $this->email->to($email);
                $this->email->subject('Example Subject');
                $this->email->message($this->load->view('frontend/register_email',$newdata,TRUE));
                $this->email->send();

                $this->session->set_userdata('email',$email);
                redirect('confirm/auth');
            }
            else {
                $data['error'] = 'Already registered!';
            }
        }
        else {
            $data['error'] = 'reCAPTCHA error';
        }
    }
    $this->load->view('frontend/layout/header');
    $this->load->view('frontend/register',$data);
    $this->load->view('frontend/layout/footer');
}

型号:

class Register_model extends CI_Model {

public function auth($email)
{
    $this->db->where('email', $email);
    $this->db->from('account');
    return $this->db->count_all_results();
}

public function insert_account($account)
{
    $this->db->insert('account',$account);
    return $this->db->insert_id();
}

public function insert_profile($profile)
{
    $this->db->insert('profile',$profile);
}

0 个答案:

没有答案