ASP实现限制一个ip只能访问一次的方法
2019-01-15 14:42:13
来源:
bacde
文章主要介绍了asp实现限制一个ip只能访问一次的方法,感兴趣的小伙伴们可以参考一下
限制一个ip只能访问一次,现在将asp代码分享给大家:
<%'/////////////////////////////////////////////////////'// //'//作用:一个IP地址只允许访问本页一次 //'//引用:<!-- #include file="Check_Ip.asp" --> //'// //'/////////////////////////////////////////////////////'Response.Charset = 936 '设置输出编码为简体中文'Response.Buffer = false '关闭缓冲区Dim Fso,ts,IpList,Cfs'设置Cookies函数Function SetCookie()Response.Cookies("IsBrow") ="Brow"Response.Cookies("IsBrow").Expires = Date+365End Function'记录IP地址函数Function WriteIp(FileName, IpAddress)Set Fso = Server.CreateObject("Scripting.FileSystemObject")Set ts = Fso.OpenTextFile(Server.MapPath(FileName),8,true)ts.WriteLine IpAddressts.CloseSet ts = NothingSet Fso = NothingEnd Function'读取IP地址函数Function ReadIpList(FileName)Set Fso = Server.CreateObject("Scripting.FileSystemObject")If Not Fso.FileExists(Server.MapPath(FileName)) ThenCreateFile("Iplist.txt")Exit FunctionEnd IfSet ts = Fso.OpenTextFile(Server.MapPath(FileName))Iplist = ts.ReadAllts.CloseSet ts = NothingSet Fso = NothingReadIpList = IplistEnd Function'创建文件函数Function CreateFile(FileName)Set Fso = Server.CreateObject("Scripting.FileSystemObject")Set Cfs = Fso.CreateTextFile(Server.MapPath(FileName))Cfs.CloseSet Cfs = NothingSet Fso = NothingEnd Function'关闭当前IE窗口函数(注:IE6下通过,其他浏览器未测试)Function CloseWindow()'Response.Write "<script>window.location='javascript:window.opener=null;window.close();'</script>"Response.Redirect"http://www.baidu.com"End FunctionIp = Request.ServerVariables("REMOTE_ADDR") '获取浏览者IP地址Cookie = Request.Cookies("IsBrow") '获取当前Cookies'Response.Write CookieIf Request.ServerVariables("HTTP_X_FORWARDED_FOR") <>""ThenResponse.Write"本站不允许使用代理访问"Response.End()ElseIf Cookie ="Brow"ThenCloseWindow()ElseIf Instr(ReadIpList("Iplist.txt"),Ip) <> 0 ThenCloseWindow()ElseWriteIp"Iplist.txt", IpEnd IfSetCookie()End IfEnd If%>
以上就是分享给大家的asp实现代码,希望对大家的学习有所帮助。