<?php

//登录和注销类
class UserLogin extends UserRequest{
	
	private $UserId;	//管理员ID
	
	private $UserName;	//管理员用户名
	
	private $Password;	//管理员密码
	
	private $SessionKey;	//SESSION秘钥
	
	//开启SESSION
	public function open_session(){
		session_start();
	}
	
	//结束SESSION
	public function close_session(){
		$_SESSION = array();
		session_unset();
		session_destroy();		
	}
	
	//判断SESSION是否存在
	private function isset_session(){
		if(isset($_SESSION['UserId']) && isset($_SESSION['UserName']) && isset($_SESSION['Password']) && isset($_SESSION['SessionKey'])){
			$this->UserId = $_SESSION['UserId'];
			$this->UserName = $_SESSION['UserName'];
			$this->Password = $_SESSION['Password'];
			$this->SessionKey = $_SESSION['SessionKey'];
			return true;
		}
		else{
			return false;
		}
	}
	
	//验证是否登录
	public function CheckLogin(){
		if($this->isset_session()){
			if($_SESSION['UserId'] !== '' && $_SESSION['UserName'] !== '' && $_SESSION['Password'] !== '' && $_SESSION['SessionKey'] !== ''){
				return true;
			}
			else{
				return false;
			}
			//验证方法待改进
		}
		else{
			return false;
		}
	}
	
	//退出登陆
	public function Logout(){
		$_SESSION['UserId'] = '';
		$_SESSION['UserName'] = '';
		$_SESSION['Password'] = '';
		$_SESSION['SessionKey'] = '';
		$this->close_session();
	}
	
	//---------------------------------
	
}

?>