Share a php user login class

Source: Internet
Author: User
Share a php user login class
In php programming, user logon is often used. here is a good php user logon class. if you need it, refer to it.

Php user logon class, code:

     ErrReport ($ this-> err_mysql); $ this-> err = $ this-> err_mysql;} function isLoggedin () // determine whether to log on to {if (isset ($ _ COOKIE ['Sid ']) // if the cookie contains sid {session_id ($ _ COOKIE ['Sid']); session_start (); $ this-> username = $ _ SESSION ['username']; $ this-> userid = $ _ SESSION ['userid']; $ this-> userlevel = $ _ SESSION ['userlevel']; return true;} else // if no sid is saved in the cookie, check session {session_start () directly (); if (isset ($ _ SESSION ['username ']) Return true;} return false;} function userAuth ($ username, $ userpass) // user authentication {$ this-> username = $ username; $ this-> userpass = $ userpass; $ query = "select * from '". $ this-> authtable. "'where' username' = '$ username';"; $ result = mysql_query ($ query); if (mysql_num_rows ($ result )! = 0) // find this user {$ row = mysql_fetch_array ($ result); if ($ row ['bannd'] = 1) // this user is banned {$ this-> errReport ($ this-> err_user); $ this-> err = $ this-> err_user; return false ;} elseif (md5 ($ userpass) ==$ row ['userpass']) // password match {$ this-> userid = $ row ['id']; $ this-> userlevel = $ row ['userlevel']; return true;} else // password mismatch {$ this-> errReport ($ this-> err_password ); $ this-> err = $ this-> err_password; return false;} else // this is not found User {$ this-> errReport ($ this-> err_username); $ this-> err = $ this-> err_username; return false ;}} function setSession () // Set session {$ sid = uniqid ('Sid '); // Generate sid session_id ($ sid); session_start (); $ _ SESSION ['username'] = $ this-> username; // assign a value to the session variable $ _ SESSION ['userid'] = $ this-> userid ;//.. $ _ SESSION ['userlevel'] = $ this-> userlevel ;//.. if ($ this-> use_cookie) // if you use cookies to save sid {if (! Setcookie ('Sid ', $ sid, time () + $ this-> cookietime, $ this-> cookiepath) $ this-> errReport ("set cookie failed ");} else setcookie ('Sid ', ", time ()-3600); // clear the sid} function userLogout () in the cookie // log off {session_start (); unset ($ _ SESSION ['username']); // clear the username if (setcookie ('Sid', ", time ()-3600) in the session )) // clear sid return true in cookie; else return false;} function errReport ($ str) // error {if ($ this-> error_report) Echo "ERROR: $ str" ;}}?>

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.