Thinkphp Pass service, verify login, log off

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.