<?
class Login
{
var $username; //用戶名
var $userpass; //密碼
var $userid; //用戶id
var $userlevel; //用戶級別
var $authtable="account"; //驗證用數據表
var $usecookie=true; //使用cookie保存sessionid
var $cookiepath='/'; //cookie路徑
var $cookietime=108000; //cookie有效時間
var $err_mysql="mysql error"; //mysql出錯提示
var $err_username="username invalid"; //用戶名無效提示
var $err_user="user invalid"; //用戶無效提示(被封禁)
var $err_password="password error"; //密碼錯誤提示
var $err; //出錯提示
var $errorreport=false; //顯示錯誤
function Login($dbserv,$dbport,$dbuser,$dbpass,$dbname) //構造函數,連接數據庫
{
if(@mysql_pconnect($dbserv.":".$dbport,$dbuser,$dbpass))
{
mysql_select_db($dbname);
}
else
{
$this->errReport($this->err_mysql);
$this->err=$this->err_mysql;
}
}
function isLoggedin() //判定是否登錄
{
if(isset($_COOKIE['sid'])) //假如cookie中保存有sid
{
session_id($_COOKIE['sid']);
session_start();
$this->username=$_SESSION['username'];
$this->userid=$_SESSION['userid'];
$this->userlevel=$_SESSION['userlevel'];
return true;
}
else //假如cookie中未保存sid,則直接檢查session
{
session_start();
if(isset($_SESSION['username']))
return true;
}
return false;
}
function userAuth($username,$userpass) //用戶認證