📄 index.asp
字号:
<%option explicit%>
<!--#INCLUDE FILE="function.asp"-->
<!--#INCLUDE FILE="config.asp"-->
<html>
<head>
<title>聊天室</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<!--注释:这里从配置文件读取title常量-->
<h1 align="center"><%=title%></h1>
<center>
<form method="post" action="index.asp">
请输入您的用户名<input type="text" name="username" size="15">
<input type="submit" name="startchat" value="进入聊天室" class="buttonstyle">
<p>请选择一个聊天室:
<%
'利用循环显示所有聊天室名称和每个聊天室的在线人员数目
Dim I
For I=0 To Ubound(allChatRoom)
'下面5句输出一个单选框
Response.Write "<br><input type='radio' name='chatroom' value='" & allChatRoom(I) & "'"
If I=0 Then
Response.Write " Checked" '这一句用来默认选中第1项
End If
Response.Write ">"
'下面两句输出聊天室名称和调用函数输出在线人数
Response.Write allChatRoom(I)
Response.Write " (在线" & AllUserName(allChatRoom(I)) & "人)"
Next
%>
</form>
</center>
<%
'如果用户输入了用户名,就执行下面的程序
If Request.Form("username")<>"" Then
'以下返回用户名、选中的聊天室名称和用户IP地址,并保存到Session中
Dim username,chatroom,IP
username=Request.Form("username")
chatroom=Request.Form("chatroom")
IP=Request.ServerVariables("REMOTE_ADDR") '返回IP地址
Session("username")=username
session("chatroom")=chatroom
Session("IP")=IP
'下面检查是否已经有人使用该用户名,如无人使用,则添加到用户名单中
If GetUserName(username,chatroom)=True Then
Response.Write "<p align='center'>已经有人使用该名称,请重新输入"
Else
'下面将该用户名保存到用户名单中
Call addUserName(username,chatroom)
'下面将该用户来到的信息保存到发言信息中
Dim strSays
strSays=Time() & "<font color='red'>来自" & Session("IP") & "的" & Session("username") & "大驾光临</font>"
Application.Lock '先锁定
Application(session("chatroom"))= Application(session("chatroom")) & "<br>" & strSays
Application.Unlock '解除锁定
'重定向到聊天主页面
response.redirect "whole.asp"
End If
End If
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -