<?PHP/** * Pass service*/classPassportserviceextendsService {/** * Verify that the user or administrator is logged in * @return Boolean*/ Public functionIslogged ($admin=false){ //$_cookie_user=cookie (' Logged_user '); $_session_username=$_session[C (' Cookie_prefix '). ' Username]; $_session_uid=$_session[C (' Cookie_prefix '). ' Uid]; $_session_isadmin=intval($_session[C (' Cookie_prefix '). ' ISAdmin ']); //Verifying Local System logins if($_session_user||$_session_uid){ if(!$admin){ return true; } ElseIf($admin&&$_session_isadmin==1){ return true; } Else{ return false; } }Else{ return false; } }
Verifying Login Submission Parameters Public functionDologin ($username,$password){ if(Empty($username) ||Empty($password)){ return false; } //$username =addcslashes ($username); $password=MD5($password); $map=Array(); $map[' username ']=$username; $map[' Password ']=$password; $uid=m ("User")->where ($map)->getfield (' uid '); //$password =md5 ($password); $uid =m ("user")->where ("Username= ' {$username} ' and password= ' {$password} ')->getfield (' uid '); if(!$uid){ return false; } Else{ return $this->online ($uid); } }
Write Cookie and session Public functionOnline$uid){ $uid=intval($uid); if($uid<=0){ return false; } Else{ $user=m ("User")->where ("uid={$uid} ")->field (' Uid,username,isadmin ')find (); if(!$user){ return false; }Else{ Header("p3p:cp=."); Cookies (' Logged_user ',$user[' username ']); $_session[C (' Cookie_prefix '). ' Username '] =$user[' username ']; $_session[C (' Cookie_prefix '). ' UID '] =$user[' UID ']; $_session[C (' Cookie_prefix '). ' ISAdmin '] =$user[' ISAdmin ']; $this->recordlogin ($user[' UID ']); return true; } } } /** * Log off local login * @return void*/ Public functionlogoutlocal () {//Logout Session unset($_session[C (' Cookie_prefix '). ' Username]); unset($_session[C (' Cookie_prefix '). ' Uid]); unset($_session[C (' Cookie_prefix '). ' ISAdmin ']); //Log Off CookiesCookies (' Logged_user ',NULL); } /** * Login record * * @param int $uid User ID*/ Public functionRecordlogin ($uid) { $login[' uid '] =$uid; $login[' IP '] =get_client_ip (); $login[' place '] = CONVERT_IP ($login[' IP ']); $login[' ctime '] = Time(); M (' Login_record ')->add ($login); } /*background Management related methods*/ //run services, System services run automatically Public functionrun () {return; } //start service, not encoded Public function_start () {return true; } //stop service, not encoded Public function_stop () {return true; } //Uninstall service, not encoded Public function_install () {return true; } //Uninstall service, not encoded Public function_uninstall () {return true; }}?>
Thinkphp Pass service, verify login, log off