简单的聊天室演示程序
一个比较基本的聊天室程序,具备最基本的“在线成员”“私聊”“清屏”“自动滚屏”等功能
这个聊天室程序是为ASP初学者学习参考而做,程序压缩包不大,20几K
下载地址:http://www.lshdic.com/download/lshdic/asp_liaotian.zip
这个聊天室是结合数据库的,由于代码分布不集中,在此只贴出用户登陆的那页代码
<% set link1=server.CreateObject("ADODB.Connection") link1.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("聊天室.mdb") set rs=link1.Execute("select * from 会员表") if request.form("ok")="" then %> <HTML> <HEAD> <META http-equiv='Content-Type' content='text/html;charset=gb2312'> <Meta name='Gemeratpr' content='网络程序员伴侣(Lshdic)2004'> <TITLE>登陆聊天室</TITLE> <STYLE> *{font-size:12px;color:;} </STYLE> </HEAD> <BODY topmargin='2' leftmargin='2'> <center> <p>风云舞者的聊天室<p> <form method='post'> 在线成员:<select style='width:125'> <% str1=0 do while not rs.eof times=DateDiff("s",rs("时间"),now) '得到“当前时间”与“会员最后操作时间”之间间隔的秒数 if times<1200 then '20分钟内的最大停塞时间 if str1=0 then str1=1:response.write "<option selected>" & rs("会员") else response.write "<option>" & rs("会员") end if end if rs.movenext loop %> </select><p> 用户名:<input type='text' maxlength='10' name='user'><p> <input type='submit' value='提交' name='ok'> </form> <% else if request.form("user")="" then response.write "你必须填写用户名":response.end if instr(request.form("user")," ")<>0 or instr(request.form("user"),"<")<>0 or instr(request.form("user"),">")<>0 or len(request.form("user"))<1 then response.write "用户名称不可以含有空格、<符号、>符号、_符号,而且最少为1个字符":response.end if request.form("user")="大家" then response.write "用户名称不可以是“大家”":response.end if rs.eof=true and rs.bof=false then rs.movefirst isolduser=0 do while not rs.eof if lcase(request.form("user"))=lcase(rs("会员")) and DateDiff("s",rs("时间"),now)<1200 then response.write "对不起,<font color=red>" & request.form("user") & "</font> 这个用户还未离线,请您另起一个名字":response.end elseif lcase(request.form("user"))=lcase(rs("会员")) and DateDiff("s",rs("时间"),now)>1200 then isolduser=1:exit do end if rs.movenext loop if isolduser=1 then '如果该会员以存在数据库中 link1.Execute "update 会员表 set 时间='" & now & "',id=" & session.SessionID & " where 会员='" & request.form("user") & "'" else link1.Execute "Insert into 会员表(会员,时间,id) values ('" & request.form("user") & "','" & now & "'," & session.SessionID & ")" end if application.Lock() application("mc_" & session.SessionID)="" '为该用户创建一个存储聊天数据的application变量中 application.UnLock() session("who")=request.form("user") '为该用户创建一个Session变量为了以后动态判断 response.Redirect "MC_allform.asp" end if %> </BODY> </HTML> 
|