LoginUtil.php 3.98 KB
<?php
/*
 * Created on 2006. 09. 25
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */ 
if(! class_exists("LoginUtil")){
	 class LoginUtil
	 {
	 	public static $spliter = 30 ;		// Seperator Ascii code
	 	//public static "211.110.140.155";
	 	 //public static $cookieDomain = "localhost";
	 	public static $cookieDomain = "localhost" ;
			
		static function getAdminUser()
		{
			$cookieStr = $_COOKIE["admMap"] ;
	 		
			if( LoginUtil::isAdminLogin() == false ){	
				$map['adminNo'] = "-1" ;
				// $map['mem_id'] = session_id() ;
			}
			else
			{
				$cookieStr = pack("H*",$cookieStr);
				
				$aUser = explode(chr(self::$spliter),$cookieStr);
	
				$map['adminNo']					=	$aUser[0] ;
				$map['adminID']			=	$aUser[1] ;
				$map['adminName']			=	$aUser[2] ;
				$map['adminPhone']			=	$aUser[3] ;
				$map['regDate']			=	$aUser[4] ;
			}
	
	 		return $map ;	
		}
		
		// 로그인 유무
		static function isAdminLogin(){
			$cookieStr = $_COOKIE["admMap"] ;
					
			return ( $cookieStr != "" ) ? true : false ;
		}
		//관리자 로그인
		static function doAdminLogin($row){
	
			if($row != null){
				$cookieStr =
	
				$row['adminNo'] 					. chr(self::$spliter) .
				$row['adminID']			. chr(self::$spliter) .
				$row['adminName']			. chr(self::$spliter) .
				$row['adminPhone']			. chr(self::$spliter) .
				$row['regDate']			. chr(self::$spliter) ;
								
				$cookieStr = bin2hex($cookieStr) ; // 16진수로 암호화
	
// 				setcookie("admMap",$cookieStr,-1,"/", self::$cookieDomain);
				setcookie("admMap",$cookieStr,-1,"/", '') ;
//				var_dump(self::$cookieDomain);
//				var_dump($_COOKIE);
				//exit;
	
				return true ;
				
			}else{
				
				return false ;
			}			
		}
		
		//admin 로그아웃
		static function doAdminLogout(){
			setcookie("admMap","",time() - 3600,"/",self::$cookieDomain) ;
		}
		
		
		
		//입력 후 로그인 - APP 로그인
		static function doAppLogin($row){
	
			if($row != null){
				$cookieStr =
				$row['userNo']			. chr(self::$spliter) .
				$row['userID']			. chr(self::$spliter) .
				$row['userPwd']			. chr(self::$spliter) .
				$row['userName']		. chr(self::$spliter) .
				$row['userType']	. chr(self::$spliter) .
				$row['userTel']			. chr(self::$spliter) .
				$row['deviceTypeID']			. chr(self::$spliter) .
				$row['deviceID']			. chr(self::$spliter) ;
								
// 				echo json_encode($row);				
				
				$cookieStr = bin2hex($cookieStr) ; // 16진수로 암호화
				
				setcookie("userMapForApp", $cookieStr, -1, "/", '') ;
				
				return true ;
				
			}else{
				
				return false ;
			}
		}
		
		
		// 어플 로그인 여부를 확인한다.
	 	static function isAppLogin()
	 	{
	 		$aUser[0] = "";
	 		if(isset($_COOKIE["userMapForApp"])) {
		 		$cookieStr = $_COOKIE["userMapForApp"] ;
		 		
				$cookieStr = pack("H*",$cookieStr);
					
				$aUser = explode(chr(self::$spliter),$cookieStr);		
	 		}
	 		return ( $aUser[0] != "" && $aUser[0] != "-1"  ) ? true : false ;
	 	}
		
		
		static function getAppUser(){
			$cookieStr = isset($_COOKIE["userMapForApp"]) ? $_COOKIE["userMapForApp"] : "" ;
			
			if(isset($_COOKIE["userMapForApp"])){
				$cookieStr = pack("H*",$cookieStr);
				//echo $cookieStr;	
				$aUser = explode(chr(self::$spliter),$cookieStr);
	
				$map['no']		=	$aUser[0] ;
				$map['id']			=	$aUser[1] ;
				$map['pwd']			=	$aUser[2] ;
				$map['name']		=	$aUser[3] ;
				$map['userType']	=	$aUser[4] ;
				$map['userTel']		=	$aUser[5] ;
				$map['deviceTypeID']=	$aUeser[6];
			}
			$aUser = explode(chr(self::$spliter),$cookieStr);

			$map['no']		=	$aUser[0] ;
			$map['id']			=	$aUser[1] ;
			$map['pwd']			=	$aUser[2] ;
			$map['name']		=	$aUser[3] ;
			$map['userType']	=	$aUser[4] ;
			$map['userTel']		=	$aUser[5] ;
			$map['deviceTypeID']=	$aUeser[6];
			
			if( LoginUtil::isAppLogin() == false )
			{	
				$map['no'] = "-1" ;
			}
	
	 		return $map ;	
		}
		
		
		static function doAppLogout(){
			setcookie("userMapForApp","",time() - 3600,"/",self::$cookieDomain) ;
		}
		
	

 	}	
}
?>