⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 member.php

📁 很不错的php聊天室源码,提供给大家学习
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
session_start();
include "include/query.php";
include "include/functions.php";
timer();
$db = new db_query;
$db->connect();
if($_GET["mode"]=="saveinfo")
{
	if(!verifyMember(session_id(),$_SESSION["username"]))
	{
		header("location:notice.php?id=".not_login);
		exit;
	}
	$db->query("update `members` set `oicq` = '".$_POST["oicq"]."',`homepage` = '".$_POST["homepage"]."',`realname` = '".$_POST["realname"]."',`email` = '".$_POST["email"]."',`age` = '".$_POST["age"]."' where `username` = '{$_SESSION["username"]}'");
	if(isset($_POST["editpassword"]))
	{
		if($db->result($db->query("select count(*) from `members` where `username` = '{$_SESSION["username"]}' and `password` = '".md5($_POST["oldpassword"])."'"),0,"count(*)"))
		{
			$db->query("update `members` set `password` = '".md5($_POST["newpassword"])."' where `username` = '{$_SESSION["username"]}'");
		}
		else
		{
			header("location:notice.php?id=".user_password_error);
			exit;
		}
	}
	header("location:notice.php?id=".editinfo_ok);
	exit;
}
if($_GET["mode"]=="login")
{		
	if(getConfig("img_verify")==1)
	{
		if($_SESSION["verifyCode"]!=$_POST["verify"])
		{
			header("location:notice.php?id=".verify_error);
			exit;
		}
	}
	$user = strtolower(trim($_POST["username"]));
	verifyName($user);
	optimizeTables();
	$result = $db->query("select `password`,`rank` from `members` where `username` = '".$user."'");
	if($db->numrows($result))
	{
		isLocked($_SERVER["REMOTE_ADDR"]);
		isForbid($user);
		iskicked($user);
		$array_result = $db->fetchArray($result);
		$itsPassword = $array_result["password"];
		if(MD5($_POST["password"])==$itsPassword)
		{
			$sql = "select * from `onlinelist` where `username`= '".$user."'";
			if($db->numrows($db->query($sql)))
			{
				header("location:notice.php?id=".in_chat);
				exit;
			}
			else
			{
				$db->query("update `members` set `loginnumbers`=`loginnumbers`+1,`lastlogintime`='".date("Y-m-d H:i:s")."' where `username` ='{$user}'");
				register_user($user,$array_result["rank"]);
			}
		}
		else
		{
			header("location:notice.php?id=".password_wrong);
			exit;
		}
	}
	else
	{
		//执行自动注册
		//检测用户合法性
		$username = chop($user);
		$username = htmlspecialchars($user);
		$now = date("Y-m-d H:i:s");
		$db->query("insert into `members` set `username` ='{$user}',`password` = '".md5($_POST["password"])."',`regip` = '{$_SERVER["REMOTE_ADDR"]}',`regtime` ='{$now}',`lastlogintime`='{$now}'");
		register_user($user,1);
	}
	exit;
}
function optimizeTables()
{
	global $db;
	if((time()-getConfig("last_optimize_time"))>getConfig("optimize_time")*60)
	{
		$db->query("optimize table `messages`");
		$db->query("optimize table `onlinelist`");
		$db->query("update `config` set `value` = '".time()."' where `name` = 'last_optimize_time'");
	}
	if($db->result($db->query("select count(*) from `messages`"),0,"count(*)")>($maxMessageNumber=getConfig("max_message_number")))
	{
		$id = $db->result($db->query("select `id` from `messages` order by `id` desc limit 1"),0,"id");
		$db->query("delete from `messages` where `id` < ".($id-$maxMessageNumber));
		if(mysql_error())
		{
			$db->query("repair table `messages`");
		}
	}
	//清除日志记录
	if(getConfig("enable_auto_clear_logs"))
	{
		if((time()-getConfig("log_last_clear_time"))>getConfig("log_clear_interval")*3600)
		{
			$db->query("delete from `logs`");
			$db->query("update `config` set `value` = '".time()."' where `name` = 'log_last_clear_time'");
		}
	}
}
function checkFull()
{
	global $db;
	$onlineNumber = $db->result($db->query("select count(*) from `onlinelist`"),0,"count(*)");
	if(!$db->result($db->query("select `inuse` from `rooms` where `id` ='{$_POST["chatroom"]}'"),0,"inuse"))
	{
		header("location:notice.php?id=".chatroom_not_inuse);
		exit;
	}
	if($onlineNumber>=getConfig("chatroom_maxonline"))
	{
		header("location:notice.php?id=".chatroom_full);
		exit;
	}
	if($db->result($db->query("select count(*) from `onlinelist` where `roomid` ='{$_POST["chatroom"]}'"),0,"count(*)")>=$db->result($db->query("select `maxonline` from `rooms` where `id` = '{$_POST["chatroom"]}'"),0,"maxonline"))
	{
		header("location:notice.php?id=".room_full);
		exit;
	}
	if($db->result($db->query("select `rank` from `members` where `username` = '{$_POST["username"]}'"),0,"rank")<$db->result($db->query("select `grade` from `rooms` where `id` ='{$_POST["chatroom"]}'"),0,"grade"))
	{
		header("location:notice.php?id=".cant_changeroom);
		exit;
	}
}
if($_GET["mode"]=="logout")
{
	//发送有人走的消息
	$message = array("private"=>"","event"=>"","from_user"=>"","type"=>"","roomid"=>"","content"=>"","to_user"=>"","title"=>"","namecolor"=>"","saycolor"=>"","face"=>"");
	$message["event"] = msg_logout;
	$message["from_user"] = $_SESSION["username"];
	$message["type"] = type_system;
	$message["roomid"] = $_SESSION["roomid"];
	addMessage($message,$db);
	$t1 = $db->result($db->query("select `lastsavecentstime` from `onlinelist` where `username` = '{$_SESSION["username"]}'"),0,"lastsavecentstime");
	$t2 = time();
	$db->query("update `members` set `cents` =`cents`+".($t2-$t1)."where `username` = '{$_SESSION["username"]}'");
	UnOnline($_SESSION["username"]);
	header("location:notice.php?id=".logout_ok);
	exit;
}
if($_GET["mode"]=="info")
{
	if(!isset($_SESSION["username"])&&!isset($_SESSION["administrator"]))
	{
		header("location:notice.php?id=".not_login);
		exit;
	}
	$infoResult = $db->query("select * from `members` where `username` = '{$_GET["username"]}'");
	if(!$db->numrows($infoResult))
	{
?>
<html>
<head>
<title>
没有找到该用户
</title
</head>
<body bgcolor="<?=getConfig("page_bgcolor")?>">
<br>
<br>
<br>
<div align="center">
对不起,没有找到该用户。<br>
<button onclick="window.close()">关闭窗口</button>
</div>
<br>
<?php
include "include/copyrights.php";
?>
</body>
</html>
<?php
exit;
	}
	$showAll = false;
	if(isset($_SESSION["administrator"])||$_SESSION["username"]==$_GET["username"])
	{
		$showAll = true;
	}
	$infoRow = $db->fetchArray($infoResult);
	$m = "该用户未登录";
	$onlineResult = $db->query("select * from `onlinelist` where `username` = '{$_GET["username"]}'");
	if($db->numrows($onlineResult))
	{
		$loginip = $db->result($onlineResult,0,"loginip");
		$useragent = $db->result($onlineResult,0,"useragent");
		$notsavecents = floor((time()-$db->result($db->query("select `lastsavecentstime` from `onlinelist` where `username` = '{$_GET["username"]}'"),0,"lastsavecentstime"))/60);
	}
	else
	{
		$notSaveCents = $m;
		$loginip = $m;
		$useragent = $m;
		$notsavecents = $m;
	}
	$infoRow["forbid"] = $infoRow["forbid"]?"是":"否";
	$infoRow["upgrade"] = $infoRow["upgrade"]?"是":"否";
	$infoRow["protected"] = $infoRow["protected"]?"是":"否";
	if(!$showAll)
	{
		//根据权限来显示用户信息
		$n = "";
		if($_SESSION["userrank"]<($eg = getConfig("enable_view_loginip")))
		{
			$loginip = $n;
		}
		if($_SESSION["userrank"]<getConfig("enable_view_grade"))
		{
			$infoRow["rank"] = $n;
		}
		if($_SESSION["userrank"]<getConfig("enable_view_nameattrib"))
		{
			$infoRow["forbid"] = $n;
			$infoRow["upgrade"] = $n;
			$infoRow["protected"] = $n;
		}
		if($_SESSION["userrank"]<getConfig("enable_view_sysinfo"))
		{
			$useragent = $n;
		}
		if($_SESSION["userrank"]<getConfig("enable_view_userinfo"))
		{
			$infoRow["email"] = $n;
			$infoRow["homepage"] = $n;
			$infoRow["oicq"] = $n;
			$infoRow["realname"] = $n;
			$infoRow["age"] = $n;
		}
	}
?>
<html>
<head>
<title>查看 <?=$_GET["username"]?> 的信息</title>
<META http-equiv="Content-Type" content="text/html;charset=gb2312">
<style type="text/css">
td
{
	font-size:13px;
}
.t
{
	border:1px solid black;
}
body{color:black;font-family:宋体;font-size:9pt;border-bottom:medium none;border-left:medium none;border-right:medium none;border-top:medium none;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px}
</style>
</head>
<body bgcolor="<?=getConfig("page_bgcolor")?>">
<table align="center" width=300 cellspacing=1 cellpadding=2 bgcolor="black">
<tr>
	<td colspan=2 bgcolor="#6699ff" align="center">
	<b>聊天资料</b>
	</td>
</tr>
<tr>
	<td width=100 align="right" bgcolor="buttonface">
	用户名&nbsp;
	</td>
	<td width=200 bgcolor="white">
	&nbsp;<?=$_GET["username"]?>
	</td>
</tr>
<tr>
	<td width=100 align="right" bgcolor="buttonface">
	用户名被禁用&nbsp;
	</td>
	<td width=200 bgcolor="white">
	&nbsp;<?=$infoRow["forbid"]?>
	</tr>
</tr>
<tr>
	<td width=100 align="right" bgcolor="buttonface">
	允许自动升级&nbsp;
	</td>
	<td width=200 bgcolor="white">
	&nbsp;<?=$infoRow["upgrade"]?>
	</tr>
</tr>
<tr>
	<td width=100 align="right" bgcolor="buttonface">
	名字受保护&nbsp;
	</td>
	<td width=200 bgcolor="white">
	&nbsp;<?=$infoRow["protected"]?>
	</tr>
</tr>
<tr>
	<td width=100 align="right" bgcolor="buttonface">
	登录次数&nbsp;
	</td>
	<td width=200 bgcolor="white">
	&nbsp;<?=$infoRow["loginnumbers"]?>
	</tr>
</tr>
<tr>
	<td width=100 align="right" bgcolor="buttonface">
	积分&nbsp;
	</td>
	<td width=200 bgcolor="white">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -