『原创』BBS用户类,功能有空连载。

楼主
『原创』BBS用户类,功能有空连载。
bbs.sql,数据库文件:
-- 建立数据库和表格。
drop database if exists MYDB;
create database MYDB;
use MYDB;
go
create table cts_user(
     id int default '0' not null auto_increment,
     username char(20) not null,
     userpass char(20) not null,
     qq int default '0',
     email char(30) default '',
     collection varchar(255) default '',
     point int default '0',
     total int default '0',
     regtime int(10),
     lastime int(10),
     regip char(15),
     lastip char(15),
     adminlevel tinyint default '0',
     status tinyint default '0',
           --adding...
     primary key(id,username),
);

insert into cts_user(username,userpass) values('chating','chating');
go
--其他的省略。。


config.php:
<?php
     class config{
           var $bRegCtrl=true;      
           var $sProName="茶亭工作室 bbs";

           function defaultConfig(){
                 //Do nothing;
           }

           function changeItems(){

           
           }

     }

     function ConnDb(){
           $sServerName="localhost";
           $iServerPort=3306;
           $sServerUser="root";
           $sDbPass="";
           $sDataName="MyDb";
           $hConn=mysql_connect($sServerName.":".$iServerPort,$sServerUser,$sDbPass) or die ('数据库连接失败');
           mysql_select_db($sDataName);
           return $hConn;
     }

     function CloseDb($hConn){
           mysql_close($hConn);
     }

?>

[COLOR=red][SIZE=3]用户类:[/SIZE][/COLOR]
user_class.php

<?php
/*
 *  名称:chating studio UserClass
 *  描述:PHP用于BBS用户的类,基于MySQL
 *  作者:chating  YuErping@163.com
 *  日期:2003/11/19
 */

require 'config.php';

class User{
     var $iUserId,$sUserName,$sUserPass,$sUserLever;
     var $sUserEmail,$iUserQq;      
     var $iCookieTime;

     function User($_sUserName,$_sUserPass){
           $this->sUserName=$_sUserName;
           $this->sUserPass=$_sUserPass;
     }

     function login(){
           $hConn=ConnDb();
           $sQuery="select username,userpass from cts_user where username='".$this->sUserName."' and userpass='".$this->sUserPass."'";
           $hResult=mysql_query($sQuery,$hConn) or die ("数据库操作请求失败");
           if($obj=mysql_fetch_object($hResult)){
                 return 1;                  //right login
           }
           else{
                 $sQuery="select username from cts_user where username='".$this->sUserName."'";
                 $hResult=mysql_query($sQuery,$hConn) or die ("数据库操作请求失败");
                 if($obj=mysql_fetch_object($hResult))
                       return 2;            //error pass!
                 else
                       return 3;            //the user is't exists
           }
     }

     function setUserSession(){
                     session_on_start();
           $_SESSION["UserName"]=$this->sUserName;
           //add continue;
     }

     function register(){
           $hConn=ConnDb();
           $objConfig=new config;
           if(!$objConfig->bRegCtrl){
                 echo "对不起,论坛目前停止注册!";
                 return false;
           }
           $sAddSql="insert into cts_user(username,userpass,point,regtime,lastime,regip,lastip) values('".$this->sUserName."','".$this->sUserPass."',10,".time().",".time().",'".$REMOTE_ADDR."','".$REMOTE_ADDR."')";
           $bReg=mysql_query($sAddSql,$hConn) or die ("数据库操作请求失败");
           //return ($bReg?true:false);
           return $bReg;
     }

     function setUserCookie(){
           setcookie("UserName",$this->sUserName,time()+604800); //604800=3600*24*7 一周的cookie时间
           setcookie("UserPass",$this->sUserPass,time()+604800);
     }

}
?>
1楼
大家帮我查漏补缺哦。。。
2楼
多多执教!!!小弟我学php的时间补是很久。。写错的地方表笑我哈。。呵呵。。
3楼
duoxie

电脑版 Page created in 0.0273 seconds with 2 queries.