asp实现限制一个ip只能访问一次的方法
限制一个ip只能访问一次,现在将asp代码分享给大家:
<%
'/////////////////////////////////////////////////////
'////
'//作用:一个IP地址只允许访问本页一次//
'//引用:<!--#includefile="Check_Ip.asp"-->//
'////
'/////////////////////////////////////////////////////
'Response.Charset=936'设置输出编码为简体中文
'Response.Buffer=false'关闭缓冲区
DimFso,ts,IpList,Cfs
'设置Cookies函数
FunctionSetCookie()
Response.Cookies("IsBrow")="Brow"
Response.Cookies("IsBrow").Expires=Date+365
EndFunction
'记录IP地址函数
FunctionWriteIp(FileName,IpAddress)
SetFso=Server.CreateObject("Scripting.FileSystemObject")
Setts=Fso.OpenTextFile(Server.MapPath(FileName),8,true)
ts.WriteLineIpAddress
ts.Close
Setts=Nothing
SetFso=Nothing
EndFunction
'读取IP地址函数
FunctionReadIpList(FileName)
SetFso=Server.CreateObject("Scripting.FileSystemObject")
IfNotFso.FileExists(Server.MapPath(FileName))Then
CreateFile("Iplist.txt")
ExitFunction
EndIf
Setts=Fso.OpenTextFile(Server.MapPath(FileName))
Iplist=ts.ReadAll
ts.Close
Setts=Nothing
SetFso=Nothing
ReadIpList=Iplist
EndFunction
'创建文件函数
FunctionCreateFile(FileName)
SetFso=Server.CreateObject("Scripting.FileSystemObject")
SetCfs=Fso.CreateTextFile(Server.MapPath(FileName))
Cfs.Close
SetCfs=Nothing
SetFso=Nothing
EndFunction
'关闭当前IE窗口函数(注:IE6下通过,其他浏览器未测试)
FunctionCloseWindow()
'Response.Write"<script>window.location='javascript:window.opener=null;window.close();'</script>"
Response.Redirect"http://www.baidu.com"
EndFunction
Ip=Request.ServerVariables("REMOTE_ADDR")'获取浏览者IP地址
Cookie=Request.Cookies("IsBrow")'获取当前Cookies
'Response.WriteCookie
IfRequest.ServerVariables("HTTP_X_FORWARDED_FOR")<>""Then
Response.Write"本站不允许使用代理访问"
Response.End()
Else
IfCookie="Brow"Then
CloseWindow()
Else
IfInstr(ReadIpList("Iplist.txt"),Ip)<>0Then
CloseWindow()
Else
WriteIp"Iplist.txt",Ip
EndIf
SetCookie()
EndIf
EndIf
%>
以上就是分享给大家的asp实现代码,希望对大家的学习有所帮助。