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

📄 index.asp

📁 这是我课程设计的时候做的聊天程序
💻 ASP
字号:
<!--#include file="config.asp"-->
<!--#include file="conn.asp"-->
<%
function existwords(s_string,s_fbdwords)
	isexists=false
	a_string=split(s_fbdwords,"	")
	n=ubound(a_string)
	for i=0 to n
		if trim(a_string(i))=s_string then
			isexists=true
			exit for
		end if
	next
	existwords=isexists
end function
Function SplitWords(mys,coun)
	dim ts,i,l
	if isnull(mys) then exit Function
	ts = 0
	For i = 1 To Len(mys)
		l = Mid(mys, i, 1)
		If Asc(l) > 0 and Asc(l) < 255 Then
			ts = ts + 1
		End If
		if i-ts/2 > coun then exit for
	Next
	If i-ts/2 > coun Then
		ts=ts\2+coun
		mys = left(mys,ts)
	end if
	SplitWords=mys
end Function
userid=request.form("userid")
if existwords(userid,forbidname)=true then
	set rs=nothing
	conn.close
	set conn=nothing
	response.write "<script language='javascript'>"&chr(13)
	response.write "<!--"&chr(13)
	response.write "alert('对不起,请重新选择一个用户名!');"&chr(13)
	response.write "window.history.go(-1);"&chr(13)
	response.write "//-->"&chr(13)
	response.write "</script>"&chr(13)
elseif  request.form("submit")="登陆" then
	userid=request.form("userid")
	password=request.form("password")
	usersex=trim(request.form("usersex"))
	if usersex<>"帅哥" and usersex<>"靓妹" then
		usersex="神秘人"
	end if
	if userid="" or password="" then
		response.write "<script language='javascript'>"&chr(13)
		response.write "<!--"&chr(13)
		response.write "alert('请将呢称和密码填写完整!');"&chr(13)
		response.write "window.history.go(-1);"&chr(13)
		response.write "//-->"&chr(13)
		response.write "</script>"&chr(13)
	elseif trim(userid)<>userid or trim(password)<>password or instr(userid,"'")>0 or instr(userid,"""")>0 or instr(password,"'")>0 or instr(password,"""")>0 then
		response.write "<script language='javascript'>"&chr(13)
		response.write "<!--"&chr(13)
		response.write "alert('用户名和密码中不得包含空格以及引号!');"&chr(13)
		response.write "window.history.go(-1);"&chr(13)
		response.write "//-->"&chr(13)
		response.write "</script>"&chr(13)
	else
		userid=SplitWords(userid,5)
		sql="select * from userinfo where userid='"&userid&"'"
		rs.open sql,conn,0,3
		if rs.bof and rs.eof then
			session("loginstatus")="logined"
			session("userid")=userid
			session("grade")=1
			rs.addnew
			rs("userid")=userid
			rs("password")=password
			rs("usersex")=usersex
			rs("regtime")=now()
			rs("logintime")=now()
			rs("timecount")=0
			rs("userip")=userip
			rs("logincount")=0
			rs("grade")=1
			rs("isonline")=true
			rs.update
			rs.close
			sql="select top 1 * from chatinfo order by puttime asc"
			rs.open sql,conn,0,3
			rs("userid")=""
			rs("sayto")=""
			rs("saycontent")="欢迎新人<span class=usrname onclick=setobj('"&session("userid")&"')>"&session("userid")&"</span>来到本聊天室!"
			rs("puttime")=now()
			rs("ispublic")=true
			rs.update
			rs.close
			response.redirect "chat.asp?ntime="&ntime
		elseif rs("password")<>password then
			rs.close
			session("loginstatus")=""
			session("userid")=""
			session("grade")=""
			response.write "<script language='javascript'>"&chr(13)
			response.write "<!--"&chr(13)
			response.write "alert('你输入的密码不正确\n\n或该用户名已经被注册,\n\n请重新选择用户名!');"&chr(13)
			response.write "window.history.go(-1);"&chr(13)
			response.write "//-->"&chr(13)
			response.write "</script>"&chr(13)
		else
			session("loginstatus")="logined"
			session("userid")=userid
			session("grade")=rs("grade")
			n_vgrade=(rs("timecount")-30)\60
			if n_vgrade>rs("grade") and n_vgrade<=maxgrade then
				rs("grade")=n_vgrade
			elseif n_vgrade>rs("grade") and n_vgrade>maxgrade then
				rs("grade")=maxgrade
			end if
			rs("logintime")=now()
			rs("userip")=userip
			rs("logincount")=rs("logincount")+1
			if isnull(rs("timecount")) then
				rs("timecount")=0
			end if
			rs("isonline")=true
			rs.update
			rs.close
			sql="select * from chatinfo order by puttime asc"
			rs.open sql,conn,0,3
			rs("userid")=""
			rs("sayto")=""
			rs("saycontent")="欢迎<span class=usrname onclick=setobj('"&session("userid")&"')>"&session("userid")&"</span>来到聊天室!"
			rs("puttime")=now()
			rs("ispublic")=true
			rs.update
			rs.close
			response.redirect "chat.asp?ntime="&ntime
		end if
	end if
	set rs=nothing
	conn.close
	set conn=nothing
else
%>
<html>
<head>
<title>欢迎光临<%=pagetitle%></title>
<meta http-equiv=Content-Language content=zh-cn>
<style type="text/css">
<!--
input,body,table{font-size:12px}
table{width:220px}
table table{width:99%}
form{margin:0;padding:0}
a{color:#000090;text-decoration:none}
a:hover{color:#ff3333;text-decoration:underline}
.awhite{color:#ffffff}
.awhite a{color:#ffffff;text-decoration:none;font-weight:500}
-->
</style>
<script language="javascript">
<!--
function issubmit(o_element,maxlen)
{
	if (wordslen(o_element.value)>maxlen)
	{
		o_element.select();
		alert("用户名最大长度为:"+maxlen/2+"个中文字符,或"+maxlen+"个字母!\n\n超出部分将会被自动截掉!");
		return false;
	}
	else
	{
		return true;
	}
}
//-->
</script>
<script language="vbscript">
<!--
Function Wordslen(mys)
	dim ts,i,l
	if isnull(mys) then
		wordslen=0
		exit Function
	end if
	ts = 0
	For i = 1 To Len(mys)
		l = Mid(mys, i, 1)
		If Asc(l) > 0 and Asc(l) < 255 Then
			ts = ts + 1
		else
			ts = ts + 2
		End If
	Next
	Wordslen=ts
end Function
//-->
</script>
</head>
<body topmargin=150 background=images/bg.gif>
<table border=1 align="center" cellpadding=0 cellspacing=0 style=border-collapse:collapse bordercolor=#111111 width=202 id=AutoNumber1 height=111>
	<tr>
		<td align=center class="awhite" style="background:#34aacd url(images/leadtop.gif);height:19px"><%=pagetitle%>--用户登陆</td>
	</tr>
	<tr>
		<td align=center height=65>
			<form method=POST action="<%=request.servervariables("script_name")%>" onsubmit="return issubmit(document.forms[0].userid,10)">
				<table border=0 cellpadding=0 cellspacing=0 style=border-collapse:collapse bordercolor=#111111 width=100% id=AutoNumber2 height=88 bgcolor=#E0E0E0>
					<tr>
						<td width=32% height=31 align=center>用户名</td>
						<td width=68% height=31><input type="text" name="userid" size=17 maxlength="10" style="font-size:12px;border-style:solid;border-width:1;padding-left:4;padding-right:4;padding-top:1;padding-bottom:1"></td>
					</tr>
					<tr>
						<td width=32% height=31 align=center>密&nbsp; 码</td>
						<td width=68% height=31><input type="password" name="password" size=17 maxlength="30" style=border-style:solid;border-width:1;padding-left:4;padding-right:4;padding-top:1;padding-bottom:1></td>
					</tr>
					<tr>
						<td width=32% height=31 align=center>性&nbsp; 别</td>
						<td width=68% height=31><select name="usersex" style="width:120px;">
						<option value="帅哥">帅哥
						<option value="靓妹">靓妹
						<option value="神秘人" selected>保密
						</select>
						</td>
					</tr>
					<tr>
						<td width=100% height=26 colspan=2><p align=center><input type=submit value="登陆" name="submit" style="font-size:12px; height:21px; width:60px; color: #E0E0E0; background-color: #006898; border: 2 solid #3399FF" onMouseOver ="this.style.backgroundColor='#ff0000'" onMouseOut ="this.style.backgroundColor='#006898'">&nbsp;<input type=reset value=重置 name=reset style="font-size:12px; height:21px; width:60px; color: #E0E0E0; background-color: #006898; border: 2 solid #3399FF" onMouseOver ="this.style.backgroundColor='#ff0000'" onMouseOut ="this.style.backgroundColor='#006898'"> <input type="button" onclick="window.location.href='../index.asp'" style="font-size:12px; height:21px; width:60px; color: #E0E0E0; background-color: #006898; border: 2 solid #3399FF" onMouseOver ="this.style.backgroundColor='#ff0000'" onMouseOut ="this.style.backgroundColor='#006898'" value="回首页"></td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
	<tr>
		<td align=center class="awhite" style="background:#34aacd url(images/leadbottom.gif);height:19px;"><a href="http://libupei.126.com" target="_blank">02(28)的网上家园</a></td>
	</tr>
</table>
</body>
</html>
<%
end if
%>

⌨️ 快捷键说明

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