【发布时间】:2013-12-23 15:05:25
【问题描述】:
我是 CodeIgniter (v.2.1.4) 的新手。我在从模型中获取帖子时遇到问题。
我有一个控制器:
class Login extends CI_Controller{
public function index(){
$data['main_view'] = 'login_form';
$this->load->view('login/include/template', $data);
}
public function validate(){
$this->load->library('form_validation');
$this->form_validation->set_rules('user', 'Име', 'trim|required|min_length[3]');
$this->form_validation->set_rules('pass', 'Парола', 'trim|required|min_length[4]');
if($this->form_validation->run()){
$this->load->model('users_model');
if($this->users_model->validate_login($username, $password)){
//valid user
}
else{
//not vlaid user
}
}
else{
$this->index();
}
}
}
还有一个模型:
class Users_model extends CI_Model{
function __construct() {
parent::__construct();
}
function validate_login(){
$username = $this->input->post('user');
$password = md5($this->input->post('pass'));
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get('users');
if($query->num_rows() == 1){
return TRUE;
}
else return FALSE;
}
}
当通过表单(post)有效对(用户名和密码)发送时,没有任何反应,但在 apache2 日志中出现:
PHP 致命错误:在 /var/www/ci/application/models/users_model.php 中的非对象上调用成员函数 where()
怎么了?
【问题讨论】:
-
请不要使用 md5 进行密码散列,它不是很安全。哈希密码时也总是使用盐。我建议你改用 php.net/manual/en/function.password-hash.php 这个。
标签: php codeigniter-2