一个用户ajax登录、cookie登录的问题
/*** 方法名: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());
}
问题是 现了退出不了了怎么办???
还有木有更好的方案 !!我是新手谢谢哈
本帖最后由 太尉天上飞 于 2012-5-1 13:26 编辑
http://www.cnblogs.com/ibjrc/archive/2011/08/19/2146062.html 问题已经解决 谢谢大家 在cookie里面存
user_passwd
似乎不好?看起来很危险啊!被人得到怎么办?
页:
[1]