停止无限循环

时间:2012-08-29 17:59:36

标签: php codeigniter-2 infinite-loop

我正在通过代码点火器构建社交网络。注册后,潜在成员将被存储在数据库中,并且其状态将被标记为待处理。然后我发送一封带有哈希标记链接的确认电子邮件。当他们点击链接时,它会将自己的帐户标记为有效,并将其带到有登录的欢迎页面。

当我进入链接时,它设置了一个无限循环,并在我使用MAMP时冻结了我的计算机。 (或者我怀疑这是一个无限循环)

以下是我的相关代码:

发送电子邮件的

auth CONTROLLER:

function varification_email()
{
    $query = $this->db->query('SELECT * FROM users order by id desc LIMIT 1');
    $token = sha1($user->email.$user->salt).dechex($user->id);
    $domain = "clci.dev/index.php";
    $link = "http://www.".$domain."/account/confirmation/?token=$token";
    foreach ($query->result() as $user)
    {
        $this->load->library('email');

        $this->email->from('noreply@cysticlife.org', 'CysticLife');
        $this->email->to($user->email); 

        $this->email->subject('Welcome to CysticLife!');
        $this->email->message("Thanks for signing up for CysticLife! To complete the registration process please go to the following web address:\n\n$link\n\n-Your friends at CysticLife\n\nPlease remember to add the cysticlife.org domain to your address book to ensure that you receive your CysticLife e-Notifications as requested.eh");    

        $this->email->send();
}

用户通过电子邮件链接回来的帐户CONTROLLER:

public function confirmation() {
    $data['main_content'] = 'account/confirmation';
    $this->load->view('includes/templates/main_page_template', $data);
    $this->load->library('encrypt');
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->model('user_model', 'um');
    $login = $this->input->post('submit');


    //IF THE SUBMIT BUTTON IS TRIGGERED THE POST DATA IS SENT TO THE VALIDATE FUNCTION IN THE MODEL VIA VARIABLES CREATED 
    if($login) {
        $user = $this->um->validate(array('email' => $this->input->post('email')));
        if( $user ) {
            // CHECK THE USER'S PASSWORD AGAINST THE ONE FROM THE LOGIN FORM
            if($user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password')))) {
                $this->session->set_userdata('logged_in', TRUE);
                $this->session->set_userdata(array(
                    'email' => $this->input->post('email')
                ));
                $this->session->userdata('logged_in');
                redirect('account/dashboard');
                exit;
            }
        }
    }

    $this->index();
}

提前致谢

1 个答案:

答案 0 :(得分:0)

varification_email()

  • 在v a rification_email()中,$user在定义之前使用。我认为真正的代码没有这个问题。
  • 您在数据库中选择用户的方法容易出现并发错误(用户返回错误)。

确认()

  • 由于Cookie太大,我已经遇到浏览器挂起,超过了4 kB。看看那个。
  • 问题可能出在user_model->validate()。注释掉以下代码并检查它是否有效。