首页 > 编程 > ASP > 正文

asp实现限制一个ip只能访问一次的方法

2024-05-04 11:10:10
字体:
来源:转载
供稿:网友

这篇文章主要介绍了asp实现限制一个ip只能访问一次的方法,感兴趣的小伙伴们可以参考一下

限制一个ip只能访问一次,现在将asp代码分享给大家:

 

 
  1. <%  
  2. '/////////////////////////////////////////////////////  
  3. '// //  
  4. '//作用:一个IP地址只允许访问本页一次 //  
  5. '//引用:<!-- #include file="Check_Ip.asp" --> //  
  6. '// //  
  7. '/////////////////////////////////////////////////////  
  8.  
  9. 'Response.Charset = 936 '设置输出编码为简体中文  
  10. 'Response.Buffer = false '关闭缓冲区  
  11.  
  12. Dim Fso,ts,IpList,Cfs  
  13.  
  14. '设置Cookies函数  
  15. Function SetCookie()  
  16. Response.Cookies("IsBrow") = "Brow" 
  17. Response.Cookies("IsBrow").Expires = Date+365  
  18. End Function  
  19.  
  20. '记录IP地址函数  
  21. Function WriteIp(FileName, IpAddress)  
  22. Set Fso = Server.CreateObject("Scripting.FileSystemObject")  
  23. Set ts = Fso.OpenTextFile(Server.MapPath(FileName),8,true)  
  24. ts.WriteLine IpAddress  
  25. ts.Close  
  26. Set ts = Nothing  
  27. Set Fso = Nothing  
  28. End Function  
  29.  
  30. '读取IP地址函数  
  31. Function ReadIpList(FileName)  
  32. Set Fso = Server.CreateObject("Scripting.FileSystemObject")  
  33. If Not Fso.FileExists(Server.MapPath(FileName)) Then  
  34. CreateFile("Iplist.txt")  
  35. Exit Function  
  36. End If  
  37.  
  38. Set ts = Fso.OpenTextFile(Server.MapPath(FileName))  
  39. Iplist = ts.ReadAll  
  40. ts.Close  
  41. Set ts = Nothing  
  42. Set Fso = Nothing  
  43. ReadIpList = Iplist  
  44. End Function  
  45.  
  46. '创建文件函数  
  47. Function CreateFile(FileName)  
  48. Set Fso = Server.CreateObject("Scripting.FileSystemObject")  
  49. Set Cfs = Fso.CreateTextFile(Server.MapPath(FileName))  
  50. Cfs.Close  
  51. Set Cfs = Nothing  
  52. Set Fso = Nothing  
  53. End Function  
  54.  
  55. '关闭当前IE窗口函数(注:IE6下通过,其他浏览器未测试)  
  56. Function CloseWindow()  
  57. 'Response.Write "<script>window.location='javascript:window.opener=null;window.close();'</script>"  
  58. Response.Redirect "http://www.baidu.com" 
  59. End Function  
  60.  
  61. Ip = Request.ServerVariables("REMOTE_ADDR") '获取浏览者IP地址  
  62.  
  63. Cookie = Request.Cookies("IsBrow") '获取当前Cookies  
  64. 'Response.Write Cookie  
  65.  
  66. If Request.ServerVariables("HTTP_X_FORWARDED_FOR") <> "" Then  
  67. Response.Write "本站不允许使用代理访问" 
  68. Response.End()  
  69. Else  
  70. If Cookie = "Brow" Then  
  71. CloseWindow()  
  72. Else  
  73. If Instr(ReadIpList("Iplist.txt"),Ip) <> 0 Then  
  74. CloseWindow()  
  75. Else  
  76. WriteIp "Iplist.txt" , Ip  
  77. End If  
  78. SetCookie()  
  79. End If  
  80. End If  
  81. %> 

以上就是分享给大家的asp实现代码,希望对大家的学习有所帮助。


注:相关教程知识阅读请移步到ASP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表