我正在使用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 );
}
}
}
来自Model的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;
}
}
使用我设置的调试消息,在提交表单后,我“让它回到控制器尝试登录”,就是这样。关于什么可能导致它的任何想法?
答案 0 :(得分:1)
在控制器中更改此条件
if ( $this->form_validation->run() === FALSE )
您可以在http://ellislab.com/codeigniter/user_guide/libraries/form_validation.html
了解更多信息