Codeigniter登录验证

时间:2015-03-15 10:38:51

标签: php mysql codeigniter

我在登录页面的验证和登录页面的验证方面也需要帮助。

控制器:      class User_authentication扩展CI_Controller {

function __construct(){
    parent::__construct();
    $this->load->helper('cookie');
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->database();
}

function index() {
    $this->session->set_userdata('message', '');
}

function loadLogin() {
    $this->load->view('index.php');
}

function authenticateUser() {
    $this->form_validation->set_rules('username', 'Username', 'callback_username_check');
    $this->form_validation->set_rules('pass', 'Password', 'trim|required|xss_clean');
    $this->form_validation->set_message('required', 'Invalid Password.');

    if($this->form_validation->run() == FALSE) {
        $this->load->view('index.php');
    }

    else {
        redirect('homepage/loadhomeView');
    }

}

function username_check($str) {
    $username = $this->input->get_post('username');

    if($str == '' || $str != $username) {
        $this->form_validation->set_message('username_check', 'The username is invalid');
        return FALSE;
    }
    else {
        return TRUE;
    }
}

function logout() {
    $this->session->sess_destroy();
    $this->load->view('index.php');
 }
}

和型号:     class User_model扩展了CI_Model {

function login_user() {

    $this->db->select('*');
    $this->db->from('users');
    $this->db->where('username', $username);
    $this->db->where('password', $password);

    $query = $this->query->get();

    if($query->num_rows() == 1) {
        return $query->result();
    }
    else {
        return false;
    }
}
}

请指导我这样做..谢谢

0 个答案:

没有答案
相关问题