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

📄 admin.php

📁 聊天程序
💻 PHP
字号:
<?php

/////////////////////////////////////////////////////////////////////////////////////////////////////////

function display()
{
$forbided_user="";
$row=file("files/lock.php");
for($i=0;$i<count($row);$i++)
	{
	if(chop($row[$i])!="")
		{
		if($i==(count($row)-1))  $forbided_user.=chop($row[$i]);
		else  $forbided_user.=chop($row[$i]).",";
		}
	}
$chatroom_name=db("get","files/system.php",1,"chatroom_name",2);
$flush_delay=db("get","files/system.php",1,"flush_delay",2);
?>
<center>
<link rel="stylesheet" href="index.files/css.css" type="text/css">
<table width=90% border=0 cellspacing=6 cellpadding=0 >
<tr><td colspan=2 align=center><font color=blue size=3>GREEN聊天室管理后台</font></td></tr>
<tr><td colspan=2 height=10 bgcolor=#FFFFFF><hr color=#aaaaaa size=1 width=100%></td></tr>
<!-- -- -- -->
<form name="main" method="post" action="admin.php?action=main_save">
<tr><td width=150>聊天室名称</td>
<td bgcolor=#FFFFFF><input type=text name=chatroom_name size=30 class=input value="<?echo$chatroom_name;?>">(不支持代码,纯文本)</td></tr>
<tr><td width=150>聊天刷新间隔</td>
<td bgcolor=#FFFFFF><input type=text name=flush_delay size=30 class=input value="<?echo$flush_delay;?>"><font color=red>(请设为1~6之间的数字,数字越大 资源消耗越小)</font></td></tr>
<tr><td width=150>被禁止的用户</td>
<td bgcolor=#FFFFFF><input type=text name=forbided_user size=30 class=input value="<?echo$forbided_user;?>">(多个请用英文逗号隔开) &nbsp; <input type=submit value=确定 class=button></td></tr>
<tr><td colspan=2 height=10 bgcolor=#FFFFFF><hr color=#aaaaaa size=1 width=100%></td></form></tr>
<!-- -- -- -->
<form name="room_admin" method="post" action="admin.php?action=addroom">
<tr><td width=150 valign=top>房间管理</td>
<td bgcolor=#FFFFFF>
<?
$row=file("files/roomlist.php");
for($i=1;$i<count($row);$i++)
	{
	$sub=explode("|",$row[$i]);
	$roomname=$sub[1];
	$row2=file("files/".$roomname."_online.php");
	for($j=0;$j<count($row2);$j++)
		{
		$sub2=explode("|",$row2[$j]);
		$timedif=time()-$sub2[2];
		if($timedif<=600)
			$all.=chop($row2[$j])."\n";
		}
	writeF("files/".$roomname."_online.php",$all,"w");
	$onlinenum=count(file("files/".$roomname."_online.php"));
	echo $roomname." (在线人数:".$onlinenum.") &nbsp;&nbsp; [<a href=admin.php?action=delroom&roomname=".$roomname.">删除房间</a>]<br>\n";
	}
?>
新增房间:<input size=20 type=text name="newroom" class=input> <input type=submit value=确定 class=button>
</td></form></tr>
<tr><td colspan=2 height=10 bgcolor=#FFFFFF><hr color=#aaaaaa size=1 width=100%></td></tr>
<!-- -- -- -->
<?
$buffer="";
$row=file("files/custom.php");
for($i=0;$i<count($row);$i++)
	$buffer.=$row[$i];
?>
<form name="room_admin" method="post" action="admin.php?action=custom_save">
<tr><td width=150 valign=top>自定义管理</td>
<td bgcolor=#FFFFFF>
<textarea name=custom class=textarea wrap=off cols=55 rows=8><?echo$buffer;?></textarea>
<input type=submit value=确定 class=button>
</td></form></tr>
<tr><td colspan=2 height=10 bgcolor=#FFFFFF><hr color=#aaaaaa size=1 width=100%></td></tr>
<tr><td width=150><a href="admin.php?action=admin_logout">登出管理</a></td><td bgcolor=#FFFFFF></td></tr>
</table>
</center>
<?
}

function admin_login_display()
{
?>
<center><br><br><br><br>
<form name="admin_login" method="post" action="admin.php?action=admin_login">
管理帐号:<input size=15 type=text name="admin_name"><br><br>
管理密码:<input size=15 type=password name="admin_pass"><br><br>
<input type=submit value=确定>
</form></center>
<?
}

function admin_login_process($admin_name,$admin_pass)
{
$system_admin_name=db("get","files/system.php",1,"admin_name",2);
$system_admin_pass=db("get","files/system.php",1,"admin_pass",2);
if($admin_name==$system_admin_name && $admin_pass==$system_admin_pass)
	session_register("admin_logined");
header("location:admin.php");
}

function admin_logout_process()
{
session_unregister("admin_logined");
header("location:index.php");
}

function main_save($chatroom_name,$flush_delay,$forbided_user)
{
$chatroom_name=safe($chatroom_name);
if(chop($chatroom_name)=="")
	die("<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>\n没有输入聊天室名称\n");
if(!eregi("^[0-9]+$",$flush_delay)  || ($flush_delay < 1 || $flush_delay > 6))
	die("<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>\n刷新间隔输入不正确\n");
db("put","files/system.php",1,"chatroom_name",2,$chatroom_name);
db("put","files/system.php",1,"flush_delay",2,$flush_delay);
$buffer="";
$sub=explode(",",$forbided_user);
for($i=0;$i<count($sub);$i++)
	if(chop($sub[$i])!="")
		$buffer.=chop($sub[$i])."\n";
writeF("files/lock.php",$buffer,"w+");
echo "<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>";
echo "修改成功,正在返回\n";
}

function addroom($newroom)
{
$newroom=safe($newroom);
$newroom=str_replace("#","",$newroom);
$newroom=str_replace("?","",$newroom);
$newroom=str_replace("=","",$newroom);
$newroom=str_replace("&","",$newroom);
if(chop($newroom)=="")
	die("<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>\n没有输入名称\n");
$row=file("files/roomlist.php");
for($i=1;$i<count($row);$i++)
	{
	$sub=explode("|",$row[$i]);
	if($newroom==$sub[1])
		die("<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>\n房间已存在,请重新命名\n");
	}
if(count(file("files/roomlist.php"))>=10)
	die("<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>\n已达到最大数\n");
else
	{
	writeF("files/".$newroom."_msg.php","1","w+");
	chmod("files/".$newroom."_msg.php",0777);
	for($i=0;$i<=9;$i++)
		{
		writeF("files/".$newroom."_msg_".$i.".php","","w+");
		chmod("files/".$newroom."_msg_".$i.".php",0777);
		}
	writeF("files/".$newroom."_online.php","","w+");
	chmod("files/".$newroom."_online.php",0777);
	$newline="|".$newroom."|shim.gif||\n";
	writeF("files/roomlist.php",$newline,"a+");
	echo "<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>";
	echo "添加成功,正在返回\n";
	}
}

function delroom($roomname)
{
$row=file("files/roomlist.php");
for($i=1;$i<count($row);$i++)
	{
	$sub=explode("|",$row[$i]);
	if($roomname==$sub[1])
		{  $rownum=$i;  break;  }
	}
if($rownum=="")
	die("<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>\n文件系统发生错误\n");
delrow("files/roomlist.php",$rownum);
unlink("files/".$roomname."_msg.php");
unlink("files/".$roomname."_online.php");
for($i=0;$i<=9;$i++)
	unlink("files/".$roomname."_msg_".$i.".php");
echo "<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>";
echo "删除成功,正在返回\n";
}

function custom_save($custom)
{
$custom=str_replace("
","",$custom);
writeF("files/custom.php",$custom,"w+");
echo "<head><meta http-equiv=\"Refresh\" content=\"2 ;url=admin.php\"></head>";
echo "修改成功,正在返回\n";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

require("index.files/fun.php");
session_start();
if($action=="")
	{
	if(session_is_registered("admin_logined"))
		display();
	else
		admin_login_display();
	}
if($action=="admin_login")
	admin_login_process($admin_name,$admin_pass);
if($action=="admin_logout")
	admin_logout_process();
if(session_is_registered("admin_logined"))
	{
	if($action=="main_save")
		main_save($chatroom_name,$flush_delay,$forbided_user);
	if($action=="addroom")
		addroom($newroom);
	if($action=="delroom")
		delroom($roomname);
	if($action=="custom_save")
		custom_save($custom);
	}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

?>

⌨️ 快捷键说明

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