php 用户管理类,一个PHP的用户管理类(no dedug!only for study not for use!!)

//[项目标识]--------------------------------------------------------

//[使用说明]-------------------------------------------------------

//[修定说明]-------------------------------------------------------

include_once "preload.php";

class user

{

private $uid,$uname,$urname,$upwd;

private $udep,$udeprole;

private $umail,$uphone,$ubphone;

private $ulogin,$ulastlogin,$ulastip;

private $urule,$active;

private $uoplog;

private $login; //是否已成功连接数据库登录

//-----------------------------------------------------------------

public function moduser($uinfoarr)

{

//根据实际uinfoarr数组内数据进行用户信息更新

//print_r($uinfoarr);

foreach($uinfoarr as

$uindex=>$uvalue)

{

//echo "$uindex

$uvalue
";

$this->$uindex = $uvalue;

}

$this->upuser();

return true;

}

//-----------------------------------------------------------------

public function upuser()

{

//更新用户信息

//一定要是成功登录的用户,这样保证对象里的数据完整

//理论上是需先调用moduser进行数据修改后才能调用本函数

if(!$this->login) return false;

$simdb = new simdb;

$sql = "update userinfo set

urname='$this->urname',upwd=md5('$this->upwd'),udep='$this->udep',udeprole='$this->udeprole',umail='$this->umail',uphone='$this->uphone',ubphone='$this->ubphone',ulogin='$this->ulogin',ulastlogin='$this->ulastlogin',ulastip='$this->ulastip',urule='$this->urule',active='$this->active',uoplog='$this->uoplog'

where uid=$this->uid";

//echo $sql;

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库执行错误!");

return true;

}

//-----------------------------------------------------------------

public function getuser(&$uinfo = "")

{

//取用户全部数据库信息至对象和用户信息数组uinfo

if(!$this->login) return false;

$simdb = new simdb;

$sql = "select * from userinfo where uname =

'$this->uname'";

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库执行错误!");

$tmp = mysql_fetch_array($tmp) or err("数据库读取错误!");

$uinfo["uid"] = $this->uid =

$tmp["uid"];

$uinfo["udep"] = $this->udep =

$tmp["udep"];

$uinfo["urname"] = $this->urname =

$tmp["urname"]; $uinfo["udeprole"] = $this->udeprole =

$tmp["udeprole"];

$uinfo["umail"] = $this->umail =

$tmp["umail"];

$uinfo["uphone"] = $this->uphone =

$tmp["uphone"];

$uinfo["ubphone"] = $this->ubphone =

$tmp["ubphone"];

$uinfo["ulogin"] = $this->ulogin =

$tmp["ulogin"];

$uinfo["ulastlogin"] = $this->ulastlogin

= $tmp["ulastlogin"];

$uinfo["ulastip"] = $this->ulastip =

$tmp["ulastip"];

$uinfo["urule"] = $this->urule =

$tmp["urule"];

$uinfo["active"] = $this->active =

$tmp["active"];

$uinfo["uoplog"] = $this->uoplog =

$tmp["uoplog"];

return true;

}

//-----------------------------------------------------------------

public function __construct($name,$pwd)

{

//初始化用户

$this->uname =

strtolower(trim(htmlspecialchars(addslashes($name))));

$this->upwd = $pwd;

$this->ulastip =

$_SERVER["REMOTE_ADDR"];

$this->login = false;

}

//-----------------------------------------------------------------

public function __destruct()

{

//对象撤销前更新已登录用户信息

if(!$this->login) return;

$simdb = new simdb;

$sql = "update userinfo set

ulastlogin=now(),ulastip='$this->ulastip' where

uname='$this->uname'";

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库操作错误!");

}

//-----------------------------------------------------------------

public function chkuser()

{

//检测数据库中是否已存在该用户

$simdb = new simdb;

$sql = "select uid from userinfo where uname =

'$this->uname'";

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库操作错误!");

if(mysql_num_rows($tmp)>0) return

true;

}

//-----------------------------------------------------------------

public function newuser()

{

//将用户对象信息写入数据库

if($this->chkuser())

err("用户名

color=red>$this->uname

已被占用,请更换注册名!");

$simdb = new simdb;

$sql = "insert into userinfo(uname,upwd)

values('$this->uname',md5('$this->upwd'))";

//echo $sql;

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库操作错误,请联系管理员或稍候再试!");

return true;

}

//-----------------------------------------------------------------

public function deluser()

{

//从数据库中删除该用户

$simdb = new simdb;

$sql = "delete from userinfo where

uname='$this->uname'";

//echo $sql;

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库操作错误,请联系管理员或稍候再试!");

return true;

}

//-----------------------------------------------------------------

public function chklogin()

{

//用户登录检测,成功返加TRUE

if($this->login) return true;

$simdb = new simdb;

$sql = "select upwd,active from userinfo where uname =

'$this->uname'";

$tmp =

mysql_query($sql,$simdb->getconn()) or

err("数据库执行错误!");

if(mysql_num_rows($tmp)!=1) return false;

$tmp = mysql_fetch_array($tmp) or err("数据库读取错误!");

if($tmp["upwd"]!=md5($this->upwd))

return false;

if(!$tmp["active"]) err("该账号处于锁定状态,请联系管理员!");

$this->login = true;

return true;

}

//-----------------------------------------------------------------

public function showuser()

{

//简单用户信息显示

$this->getuser(); //显示用户前先取用户

?>

 
 

用户信息

登录名:=$this->uname?>

姓名:=$this->urname?>

上次登录:=$this->ulastlogin?>

@

=$this->ulastip?> 第=$this->ulogin?>次登录!

电话:=$this->uphone?>/=$this->ubphone?>

EMAIL:=$this->umail?>

操作日志:=$this->uoplog?>

----------------------------------

}

//-----------------------------------------------------------------

}

//用户信息更新示例

$uinfo = new user("meineson","mbstudio");

if($uinfo->chklogin())

{

// if($uinfo->getuser())

// {

$uinfo->showuser();

// }

}

else echo "登录失败!!";

$newuinfo["urname"] = "真实姓名";

$newuinfo["uphone"] = "05101388468";

$newuinfo["upwd"] = "mbstudio";

$uinfo->moduser($newuinfo);

//$uinfo->getuser();

$uinfo->showuser();

//$uinfo->upuser();

//-----------------------------------------------------------------

?>

数据库文件:

表:userinfo(用户信息表)

uid int(6) 用户编号

uname varchar(15) 用户登录名

upwd varchar(32) 用户密码(md5串)

urealname varchar(10) 用户姓名

udep int(4) 部门编号

udeprole int(4) 职务编号

urule varchar(100) 权限表对应置位(另附权限表及权限检测函数)

umail varchar(30) 用户邮箱

uphone varchar(15) 用户电话

ubphone varchar(15) 备用电话

ulogin int(6) 登录次数

ulastlogin datatime 上次登录时间

ulastip varchar(15) 上次登录IP

uoplog blob 操作日志

active

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值