ASP 限制发帖时间 和 登陆限制

新建立一个ASP文件 把 以下代码复制进去

<%
ip=request.ServerVariables("REMOTE_ADDR") '获取来访的IP地址

dim conn
set conn=server.CreateObject("ADODB.connection")
conn.open "Dbq="&server.MapPath("yb/dat/data.mdb")&";Driver={Microsoft Access Driver (*.mdb)}" '建立数据库连接 这里你可以自己改

sql="select * from ip_user where ip地址='"&ip&"'"
set rs=server.CreateObject("ADODB.recordset")
rs.open sql,conn,3,3
if rs.eof then
call ip_fir("thenew")
else
vistime=rs("访问时间")
if DateDiff("h",vistime,now)>=12 then
call ip_fir("theup")
else
call ip_notfir
end if
end if
%>

<%'--------------为了方便写成了过程形式:

Sub Ip_fir(action)'---------------------第一次访问的过程
response.write "12小时内,你是第一次访问本站,这里贴上加流量代码"

if action="theup" then
rs("访问时间")=now()
rs.update
elseif action="thenew" then
sql1="insert into ip_user(ip地址) values ('"&request.ServerVariables("REMOTE_ADDR")&"')"
conn.execute(sql1)
end if
End Sub

Sub ip_notfir()''---------------------12小时内访问过的过程
'---------------------这里改成你期待的处理方式
response.write "你在最近12小时内访问过本站"
End Sub
%>

 

 

check_inTime是时间Time(比如8:30:00)
tuihour=hour(rs("check_inTime"))
tuiMinute=Minute(rs("check_inTime"))
chaotime=TimeSerial(tuihour,tuiMinute+10,0)'用这个时间函数返回一个时间!就是往后加10分钟。如果是check_inTime是8:30:00,那么返回时间为:8:40:00 。
if chaotime>time then
Response.Redirect("cuo.asp?id=3")'错误处理页面!可以在这定义说十分钟后才能够注册!
end if

 

 

 

登陆错误5次锁定30分

If LoginType = "一般管理员" Then
sql = " Select * From 企业之星管理员资料表 Where 管理员登录ID = '" & User & "' "
DBRs.Open sql,DBConn,1,3
If DBRs.EOF Then
DBRs.Close
Set DBRs = Nothing
DBConn.Close
Set DBConn = Nothing
Response.Write "<script>alert('用户名或者密码错误,请重新输入');history.back();</script><br><p>"
Response.End
Else
'============================================================================

If Application(Request.Form("User") & "LoginCount")="" Then
Application.Lock
Application(Request.Form("User") & "LoginCount")=0
Application(Request.Form("User") & "LockTime")=DateAdd("N",30,Now)
Application.UnLock
End If
If Application(Request.Form("User") & "LoginCount")=5 And Application(Request.Form("User") & "UnLockTime")="" Then
Application(Request.Form("User") & "UnLockTime")=DateAdd("N",30,Now)
'添加在规定时间内超过5次登录的操作
End If
If Not (Application(Request.Form("User") & "UnLockTime")>Now And Application(Request.Form("User") & "UnLockTime")<>"") Then
If Application(Request.Form("User") & "LockTime")<Now Then
Application.Lock
Application(Request.Form("User") & "LoginCount")=0
Application(Request.Form("User") & "LockTime")=DateAdd("N",30,Now)
Application(Request.Form("User") & "UnLockTime")=""
Application.UnLock
End If
'============================================================================
ConfirmPass = DBRs("管理员登录密码")
logintime=DBRs("最后登陆时间")
lasterrtime=DBRs("最后登陆失败时间")
addtime=now()
addip=Request.ServerVariables("REMOTE_ADDR")
If Pass <> ConfirmPass Then
DBRs("最后登陆失败时间")=now
DBRs.update
DBRs.Close
Set DBRs = Nothing
DBConn.Close
Set DBConn = Nothing
'============================================================================
Application.Lock
Application(Request.Form("User") & "LoginCount")=Application(Request.Form("User") & "LoginCount")+1
Application.UnLock
'============================================================================
Response.Write "<script>alert('用户名或者密码错误,请重新输入');history.back();</script><br><p>"
Response.End
Else

Session("DBConnectString") = DBConnectString
Session("LoginType") = LoginType
Session("User") = DBRs("管理员登录ID")
Session("UserPhoneNumber")=DBRs("管理员登录ID")
Session("UserPhoneNum")=DBRs("管理员登录ID")
Session("Company") = DBRs("注册号")
Session("Islogin") = 1
session("lasterrtime")=DBRs("最后登陆失败时间")
session("lastlogintime")=DBRs("最后登陆时间")
DBRs("最后登陆时间")=addtime
DBRs("最后登陆ip")=addip
DBRs.update
DBRs.Close
Set DBRs = Nothing
DBConn.Close
Set DBConn = Nothing
'============================================================================
Application.Lock
Application(Request.Form("User") & "LoginCount")=""
Application(Request.Form("User") & "LockTime")=""
Application(Request.Form("User") & "UnLockTime")=""
Application.UnLock
'============================================================================
' Response.Write "<script Language='Javascript'>alert('登录成功');</script><br><p>"
Response.Write "<script language='vbscript'>Window.Location=""Home.asp""</script><br><p>"

Response.End
End If
'============================================================================
Else
Response.Write "<script>alert('连续5次操作失败,帐号被系统锁定,请30分钟再登陆');history.back();</script><br><p>"
End If
'============================================================================
End If
Else   
   

 

类别:默认分类 | | 添加到搜藏 | 分享到i贴吧 | 浏览( 75) | 评论 (0)
登录后,您就出现在这里。

你可能感兴趣的:(session,Microsoft,user,application,VBScript,asp)