php原生实现七天免登录

pdo_find($sql);
		if(!empty($data)){
			if(md5($pwd)==$data['loginpwd']){
				setcookie("userInfo",serialize($data),time()+3600*24*7);
				$session = array("id"=>$data['id'],'loginname'=>$data['loginname'],"nackname"=>$data['nackname']);
				$_SESSION['admin_session']=$session;
				sendmsg("登录成功","index.php");
			}else{
				sendmsg("账号或密码错误!");
			}
		}else{
			sendmsg("账号不存在!");
		}
	}else{  //不记住密码
		$sql = "select * from admins where loginname='$name'";
		$data = $pdo->pdo_find($sql);
		if(isset($_COOKIE['userInfo'])){   //有COOKIE 正常登录
			if(!empty($data)){
				if($pwd==$data['loginpwd']){
					$session = array("id"=>$data['id'],'loginname'=>$data['loginname'],"nackname"=>$data['nackname']);
					$_SESSION['admin_session']=$session;
					sendmsg("登录成功","index.php");
				}else{
					sendmsg("账号或密码错误!");
				}
			}else{
				sendmsg("账号不存在!");
			}
		}else{  //既不记住密码,也没有cookie
			if(!empty($data)){
				if(md5($pwd)==$data['loginpwd']){
					$session = array("id"=>$data['id'],'loginname'=>$data['loginname'],"nackname"=>$data['nackname']);
					$_SESSION['admin_session']=$session;
					sendmsg("登录成功","index.php");
				}else{
					sendmsg("账号或密码错误!");
				}
			}else{
				sendmsg("账号不存在!");
			}
		}
	}
	
?>

你可能感兴趣的:(PHP)