|
PHP复制代码 /**
* 方法名:login
* 作用:显示用户登录页面
*/
public function login (){
$username = get_cookie ('user_name');
$passwd = get_cookie ('user_passwd');
if(!empty($username) && !empty($passwd)){
$this->login_cookie($username,$passwd);
}else{
$this->load->view('login');
}
}
/**
* 方法名:getLogin
* 作用:验证登录信息
*/
public function getLogin (){
$user_name=strtolower(trim($this->input->post('user_name')));
$password = md5(trim($this->input->post('password')));
if(!empty($user_name) && !empty($password)){
$query = $this->user->userLogin($user_name,$password);
foreach($query as $user){};
if($user){
$this->session->set_userdata($user);
if($this->input->post('c0') == 'true'){
$this->_cookie ($user['user_name'],$user['user_passwd']);
}
echo true;
}else{
echo '用户名或密码错误!'; //失败跳回产首页
}
}else{
echo '用户名密码不能为空'; //用户名密码不能为空
}
}
/**
* 方法名:cookie
* 作用:写入cookie
*/
private function _cookie ($user,$pwd){
set_cookie ('user_name',$user,86400 * 14);
set_cookie ('user_passwd',$pwd,86400 * 14);
}
/**
* 方法名:del_cookie
* 作用:删除cookie
*/
private function del_cookie ($username,$passwd){
delete_cookie ($username);
delete_cookie ($passwd);
}
/**
* 方法名:login_cookie
* 作用:使用cookie登录
**/
public function login_cookie ($username,$passwd){
$login = $this->user->userLogin($username,$passwd);
if($login){
foreach($login as $user){};
$this->session->set_userdata($user);
redirect ('home');
//echo true;
}else{
$this->del_cookie($username,$passwd);
redirect ('login');
//echo '用户名或密码错误 !';
}
}
/**
* 方法名:logout
* 作用:退出用户登录
*/
public function logout (){
$this->session->sess_destroy(); //销毁SEESSION
$this->del_cookie($this->session->userdata['user_name'],$this->session->userdata['user_passwd']);
redirect (base_url ());
}
复制代码
问题是 现了退出不了了怎么办???
还有木有更好的方案 !!我是新手 谢谢哈
|
|