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

📄 adminspeak.asp

📁 一个网站聊天室的模型
💻 ASP
字号:
<%@ Language=VBScript CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--声明HTML语言的版本信息-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>信息发送</title>
<!--实现鼠标移到链接上时链接便以红色字体、粗体显示效果的CSS样式表-->
<style fprolloverstyle>
A:hover {color: red; font-weight: bold}
</style>
</head>
<body>
<!--对发送信息的目标用户和发送信息内容的控制-->
<script language="javascript">
<!--
	function check()
	{
		if (document.message.userid.selectedIndex==0 )
		{
			document.message.userid.multiple=false
		}
		else
		{
			document.message.userid.multiple=true
		}
	}
	
	function check1()
	{
		var ssubmit
		ssubmit=true
		if (document.message.userid.options[0].value=="none")
		{
			window.alert ("没有在线用户!")
			ssubmit=false

		}
		
		if (document.message.content.value =="")
		{
			window.alert ("请输入信息内容!")		
			ssubmit=false
		}
		return ssubmit
	
	}

//-->
</script>
<%
'这部分代码与下面的if Request.ServerVariables ("REQUEST_METHOD")="POST" then语句中的内容基本相同,可参考其中的注释

'如果用户通过管理员登录验证,就...
if session("admin_pass")="ok" then
	'这个条件控制有2个方面的重要作用:一方面是如果在其他页面(onlineadmin.asp和useradmin.asp)中通过管理员登录过,
	'进入该页面时就直接执行这个if语句中的代码,就用不到该页面后半部分if Request.ServerVariables ("REQUEST_METHOD")="POST" then语句中的代码
	'另一方面是在提交本页面中管理内容时不必重新进行管理员帐号,密码和权限的验证就可以直接提交到数据库中


	'创建数据库连接对象
	set newconn=server.CreateObject ("ADODB.Connection")
	dbpath=server.mappath("chatroom.mdb")
	newconn.open "driver={Microsoft Access Driver (*.mdb)};dbq="&dbpath
	
'如果发送信息内容不为空,就...
if Request.Form ("content")<>"" then
'逐项确定发送信息目标用户
				for each item in Request.Form ("userid")
				'如果是对所有人说的话,就对每一个在线用户发送此信息;如果不是,就对特定用户发送此信息
					if item="all" then
						newsql="select OnLineUserID from UserOnLine"
						set temprecord=newconn.Execute (newsql)
						do while not temprecord.eof
							application(temprecord(0))="<br>管理员对你说:<br><font color=purple size=4>" & Request.Form ("content") & "</font><br><br>" & application(temprecord(0))
							temprecord.movenext
						loop
						'关闭记录集对象
						temprecord.close
						set temprecord=nothing
						exit for'退出for循环
					else
					
						application(item)="<br>管理员对你说:<br><font color=purple size=4>" & Request.Form ("content") & "</font><br><br>" & application(item)
					end if
				next
			end if
		'判断是否有在线用户
			newsql="select OnLineUserID,NickName from UserOnLine"
			set newrecord=newconn.Execute (newsql)
%>
<p align="center"><font size="6" face="华文琥珀" width="200">信息发送</font></p>
<form method="POST"  action="adminspeak.asp" name="message" onSubmit="return check1()">
  <p align="center">
    <select size="9" cols="36" name="select" multiple onclick="check()">
      <%
	if newrecord.bof then
%>
      <option value="none">没有在线用户</option>
      <%
	else
%>
      <option value="all" selected>所有人</option>
      <%
	end if
%>
      <%
'列出所有在线用户
			do while not newrecord.eof
%>
      <option value="<% =newrecord(0) %>">
      <% =newrecord(1) %>
      </option>
      <%
				newrecord.movenext
			loop
%>
    </select>
    <textarea rows="8" name="content" cols="36"></textarea>
  </p>
  <table width="109" border="0" align="center">
    <tr>
      <td width="60"><div align="center">
          <input type="submit" value="提交" name="B1">
        </div></td>
      <td width="10"><div align="center"></div></td>
      <td width="60"><div align="center">
          <input type="reset" value="重置" name="B2">
        </div></td>
    </tr>
  </table>
</form>
<!--链接到用户信息管理和在线用户管理页面-->
<center>
  <a href="useradmin.asp">注册用户管理</a>
</center>
<center>
  <a href="onlineadmin.asp">在线用户管理</a>
</center>
<%
'关闭记录集对象
			newrecord.close
			set newrecord=nothing
			'关闭数据源连接对象
			newconn.Close
			set newconn=nothing
else     '这个else是与if session("admin_pass")="ok" then语句相对应的

'如果不是通过POST方法将信息提交到该页面的,即是直接进入该页面而没有经过管理员登录界面,就显示管理员登录界面,
'让用户输入管理员帐号和密码进行管理员身份验证
if Request.ServerVariables ("REQUEST_METHOD")<>"POST" then'注意这里使用的是不等号“<>”
'这部分是用户直接请求该页面时的处理过程
'因为有if session("admin_pass")="ok" then语句的控制,所以如果在其他页面(onlineadmin.asp和useradmin.asp)中通过管理员登录过,
'即session变量已经被赋值为ok,那么当请求进入该页面时就用不到这部分的,而只用到上面那些代码
'但如果用户没有在其他页面(onlineadmin.asp和useradmin.asp)中登录过管理员页面,当直接请求该页面时,就要用到这部分进行管理员登录界面的验证

	userid=Request.Form ("userid")
	
%>
<!--要求用户输入管理员帐号和密码的表单-->
<form method="POST" action="adminspeak.asp" name="check">
  <p>
  <div align="center">
    <center>
      请输入帐号:
      <input name="Admin_UID"  type="text" maxlength="10">
    </center>
  </div>
  </p>
  <div align="center">
    <center>
      <p> 请输入密码:
        <input name="Admin_PWD"  type="password" maxlength="10">
      </p>
      <table width="122" border="0" align="center">
        <tr>
          <td><div align="center">
              <input type="submit" value="提交"  name="B1">
            </div></td>
          <td><div align="center"></div></td>
          <td><div align="center">
              <input type="reset" value="重写" name="B2">
            </div></td>
        </tr>
      </table>
    </center>
  </div>
</form>
<%
'如果是通过POST方法将信息提交到该页面的,即是通过本页面中的管理员登录表单登录到该页面的,
'就判断管理员帐号和密码是否正确,他的权限是否是9,即是否具有管理员权限

else      '与if Request.ServerVariables ("REQUEST_METHOD")<>"POST" then语句相对应

'创建数据库连接对象
	set newconn=server.CreateObject ("ADODB.Connection")
	dbpath=server.mappath("chatroom.mdb")
	newconn.open "driver={Microsoft Access Driver (*.mdb)};dbq="&dbpath
	
'从user表中查找用户的帐号和密码是否正确
	newsql="select Right from user where UserID='" & Request.Form ("Admin_UID") & "' and PWD='" & Request.Form ("Admin_PWD") & "'"
	set newrecord0=newconn.Execute (newsql)
	if newrecord0.bof then
		Response.Write ("密码和帐号输入错误!<br>")
	else
	'如果没有管理员权限
		if newrecord0(0)<>9 then
			Response.Write ("你没有权限进入!")
			Response.End 
		else
		
		'如果帐号和密码都正确,而且具有管理员权限,就定义一个session变量记录管理员登录成功
		'这不仅是为了在登录其他管理页面时不必重新进行管理员帐号,密码和权限的验证,
		'同时保证了在提交本页面中管理内容时不必重新进行管理员帐号,密码和权限的验证
		session("admin_pass")="ok"	
		'如果管理员发送信息内容不为空
			if Request.Form ("content")<>"" then
			'逐项检查该页面中的选择发送信息的对象的列表框userid
				for each item in Request.Form ("userid")
				'如果是对所有人发言
					if item="all" then
					'从在线用户表中查找所有用户的帐号
						newsql="select OnLineUserID from UserOnLine"
						set temprecord=newconn.Execute (newsql)
						'通知所有在线用户管理员的发言内容
						do while not temprecord.eof
							application(temprecord(0))="<br>管理员对你说:<br><font color=purple size=4>" & Request.Form ("content") & "</font><br><br>" & application(temprecord(0))
							temprecord.movenext
						loop
						'关闭记录集对象
						temprecord.close
						set temprecord=nothing
						exit for'退出for循环
					else      '与if item="all" then语句相对应
					'如果是对某特定用户说的话
						application(item)="<br>管理员对你说:<br><font color=purple size=4>" & Request.Form ("content") & "</font><br><br>" & application(item)
					end if      '与if item="all" then语句相对应
				next
			end if      '与if Request.Form ("content")<>"" then语句相对应
		'从在线用户表中查找所有用户的用户名和昵称
			newsql="select OnLineUserID,NickName from UserOnLine"
			set newrecord=newconn.Execute (newsql)
%>
<p align="center"><font size="6" face="华文琥珀" width="200">信息发送</font></p>
<form method="POST"  action="adminspeak.asp" name="message" onSubmit="return check1()">
  <p align="center">
    <select size="9" cols="36" name="userid" multiple onclick="check()">
      <%
	  '如果没有在线用户
	if newrecord.bof then
%>
      <option value="none">没有在线用户</option>
      <%
	else'如果有在线用户,默认是对所有人发言
%>
      <option value="all">所有人</option>
      <%
	end if
%>
      <%
	  '列出所有在线用户,在列表中显示其昵称,但昵称对应的值是用户的帐号,因为只有用户帐号才能唯一确定一个用户
			do while not newrecord.eof
%>
      <option value="<% =newrecord(0) %>"><!--newrecord(0)是用户的帐号-->
	  <% =newrecord(1) %><!--newrecord(1)是用户的昵称-->
      </option>
      <%
				newrecord.movenext
			loop
%>
    </select>
    <textarea rows="8" name="content" cols="36"></textarea>
    <br>
    <input type="submit" value="提交" name="B1">
    <input type="reset" value="重置" name="B2">
  </p>
  </center>
  </div>
</form>
<center>
<!--链接到用户信息管理和在线用户管理页面-->
  <a href="useradmin.asp">注册用户管理</a>
</center>
<center>
  <a href="onlineadmin.asp">在线用户管理</a>
</center>
<%
'关闭记录集对象
			newrecord.close
			set newrecord=nothing
			'关闭数据源连接对象
			newconn.Close 
			set newconn=nothing
		end if      '与if newrecord0(0)<>9 then语句相对应
	end if      '与if newrecord0.bof then语句相对应
end if      '与if Request.ServerVariables ("REQUEST_METHOD")<>"POST" then语句相对应
end if      '与if session("admin_pass")="ok" then语句相对应

%>
</body>
</html>

⌨️ 快捷键说明

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