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

ASP教程 2025-08-07

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

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

  1. <%
  2. '/////////////////////////////////////////////////////
  3. '////
  4. '//作用:一个IP地址只允许访问本页一次//
  5. '//引用://
  6. '////
  7. '/////////////////////////////////////////////////////
  8. 'Response.Charset=936'设置输出编码为简体中文
  9. 'Response.Buffer=false'关闭缓冲区
  10. DimFso,ts,IpList,Cfs
  11. '设置Cookies函数
  12. FunctionSetCookie()
  13. Response.Cookies(IsBrow)=Brow
  14. Response.Cookies(IsBrow).Expires=Date+365
  15. EndFunction
  16. '记录IP地址函数
  17. FunctionWriteIp(FileName,IpAddress)
  18. SetFso=Server.CreateObject(Scripting.FileSystemObject)
  19. Setts=Fso.OpenTextFile(Server.MapPath(FileName),8,true)
  20. ts.WriteLineIpAddress
  21. ts.Close
  22. Setts=Nothing
  23. SetFso=Nothing
  24. EndFunction
  25. '读取IP地址函数
  26. FunctionReadIpList(FileName)
  27. SetFso=Server.CreateObject(Scripting.FileSystemObject)
  28. IfNotFso.FileExists(Server.MapPath(FileName))Then
  29. CreateFile(Iplist.txt)
  30. ExitFunction
  31. EndIf
  32. Setts=Fso.OpenTextFile(Server.MapPath(FileName))
  33. Iplist=ts.ReadAll
  34. ts.Close
  35. Setts=Nothing
  36. SetFso=Nothing
  37. ReadIpList=Iplist
  38. EndFunction
  39. '创建文件函数
  40. FunctionCreateFile(FileName)
  41. SetFso=Server.CreateObject(Scripting.FileSystemObject)
  42. SetCfs=Fso.CreateTextFile(Server.MapPath(FileName))
  43. Cfs.Close
  44. SetCfs=Nothing
  45. SetFso=Nothing
  46. EndFunction
  47. '关闭当前IE窗口函数(注:IE6下通过,其他浏览器未测试)
  48. FunctionCloseWindow()
  49. 'Response.Write
  50. Response.Redirecthttp://www.b*a**idu.com
  51. EndFunction
  52. Ip=Request.ServerVariables(REMOTE_ADDR)'获取浏览者IP地址
  53. Cookie=Request.Cookies(IsBrow)'获取当前Cookies
  54. 'Response.WriteCookie
  55. IfRequest.ServerVariables(HTTP_X_FORWARDED_FOR)<>Then
  56. Response.Write本站不允许使用代理访问
  57. Response.End()
  58. Else
  59. IfCookie=BrowThen
  60. CloseWindow()
  61. Else
  62. IfInstr(ReadIpList(Iplist.txt),Ip)<>0Then
  63. CloseWindow()
  64. Else
  65. WriteIpIplist.txt,Ip
  66. EndIf
  67. SetCookie()
  68. EndIf
  69. EndIf
  70. %>

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

注:相关教程知识阅读请移步到ASP教程频道。