0

我正在为codeigniter开发一个登录系统,提交登录表单后,页面只是空白。我有以下代码,插入了 echo 以帮助我找出问题所在。

我在 index.php 模式中设置了开发模式,在 php.ini 中设置了 E_ALL 并在其他一些页面上成功接收错误。

/account/login 的控制器:

public function login()
{
    echo "made it back into controller";
    $this->load->helper('form');
    $this->load->library('form_validation');

    $data['title'] = "Log in";

    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

    if ( $this->form_validation->run() === FALSE )
    {
        echo "unable to validate";
        $this->load->view('templates/header', $data);
        $this->load->view('account/login', $data);
        $this->load->view('templates/footer', $data );
    } 
    else
    {
        echo "attempting to login";
        if ( $this->account_model->login() == FALSE ) 
        {
            echo "failed";
            $this->load->view('templates/header', $data);
            $this->load->view('account/login', $data);
            $this->load->view('templates/footer', $data );
        }
        else
        {
            echo "success";
            $this->load->view('templates/header', $data);
            $this->load->view('account/successfullogin', $data);
            $this->load->view('templates/footer', $data );
        }
    }

}

模型中的 login() 方法,由控制器调用:

public function login ()
{

    require 'application/libraries/PasswordHash.php';

    $t_hasher = new PasswordHash(8, FALSE);
    $password = $this->input->post('password');
    $hash = $t_hasher->HashPassword($password);
    echo "hashed";

    $query = $this->db->query('SELECT `login_token` FROM `Users` WHERE `username` = "'.$this->input->post('username').'" AND `password` = "'. $this->input->post('password').'"');

    echo "query made";
    $rowCount = $query->num_rows();
    echo "query counted";

    if ( $rowCount == 1 ) {
        echo "found row";
        $token = $query->result_array();
        echo "found token";
        $this->input->set_cookie( 'session_token', $token['login_token'], time()+259200, '/', 'notyetcreated.phpfogapp.com');
        echo "cookie created";
        return TRUE;
    } else {
        echo "no beans";
        return FALSE;
    }
}

使用我设置的调试消息,在提交表单后,我得到“让它回到控制器尝试登录”,就是这样。关于可能导致它的任何想法?

4

1 回答 1

1

在控制器中更改此条件

 if ( $this->form_validation->run() === FALSE )

您可以在http://ellislab.com/codeigniter/user_guide/libraries/form_validation.html了解更多信息

于 2012-10-10T08:43:20.987 回答