我對Codeigniter有點新,所以我需要一些幫助,如果你可以在這裏發佈答案。謝謝。如何將userid設置爲codeigniter中的會話數組?
這裏是我的控制器:
public function login()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|min_length[3]');
$this->form_validation->set_rules('passwd', 'Passwd', 'required|min_length[3]');
$data = array();
if ($this->form_validation->run())
{
$email = $this->input->post('email');
$passwd = $this->input->post('passwd');
$this->load->model('user_model');
if ($this->user_model->check($email, $passwd))
{
$this->session->set_userdata('user', $email);
redirect(base_url('/'));
}
else
{
$data['error'] = 'Wrong e-mail or password.';
}
}
$this->load->view('login', $data);
}
,這裏是我的型號:
public function __construct()
{
// Call the CI_Model constructor
parent::__construct();
}
public function check($email = NULL, $password = NULL)
{
$this->db->select('id');
$this->db->where('email', $email);
$this->db->where('password', sha1($password));
$this->db->limit(1);
$result = $this->db->get('php_users_login');
return ($result->num_rows() == 1);
}
我希望把用戶ID到會話(數據庫結構像ID,電子郵件,密碼...)
謝謝你的幫助!
你最歡迎@gazrobur –
我有正確的尤爾可變http://stackoverflow.com/posts/34921382/revisions – devpro
非常感謝你@devpro –