class Login extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
if ($this->session->userdata('username')) {
redirect('admin/main');
}
$this->load->library('form_validation'); // 使用CI的表单验证, 如下:
$this->form_validation->set_rules('username', '用户名', 'min_length[4]|required');
$this->form_validation->set_rules('password', '密码', 'min_length[4]|required');
if($this->form_validation->run() !== false){
// then validate password. Get from the Db.
$this->load->model('m_admin_login');
$res = $this->m_admin_login->check_user(
$this->input->post('username'),
$this->input->post('password')
);
if($res !== false){
//print_r($res);
$this->session->set_userdata('username',$this->input->post('username'));
//$this->session->set_userdata('userid',res['a_id']);
redirect('admin/main');
}
}
$this->load->view('admin/login');
}
public function out_login()
{
$this->session->unset_userdata('username');
//$this->session->sess_destroy();
redirect('admin/login');
}
}