asp实现限制一个ip只能访问一次的方法(Apache访问控制的两种)不要告诉别人

随心笔谈2个月前发布 admin
194 00
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

文章摘要

本文介绍了一段 ASP 代码,主要用于管理访问 IP 地址的功能,包括以下几个核心部分: 1. **设置 Cookie 函数(SetCookie)**:用于在客户端存储访问记录,记录当前浏览器是否登录状态。 2. **记录 IP 地址函数(WriteIp)**:将访问到的 IP 地址写入到指定的文本文件中。 3. **读取 IP 地址列表函数(ReadIpList)**:从文件中读取已记录的 IP 地址列表。 4. **判断 IP 地址是否被访问过多**:通过检查当前 IP 地址是否在读取的列表中,决定是否允许访问该页面。 5. **处理代理访问**:通过检查 `HTTP_X_FORWARDED_FOR` 头程变量,判断用户是否为代理访问,如果是则返回错误提示。 6. **关闭 IE 窗口函数(CloseWindow)**:用于在 IE 浏览器中关闭当前窗口,以防止多线程访问。 文章主要目的是实现 IP 地址的多线程访问控制功能,适用于反垃圾邮件、防多线程访问等场景。代码中涉及的函数和逻辑设计简洁明了,能够有效实现IP地址的管理功能。


<%
‘/////////////////////////////////////////////////////
‘// //
‘//作用:一个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+365
End Function

‘记录IP地址函数
Function WriteIp(FileName, IpAddress)
Set Fso=Server.CreateObject(“Scripting.FileSystemObject”)
Set ts=Fso.OpenTextFile(Server.MapPath(FileName),8,true)
ts.WriteLine IpAddress
ts.Close
Set ts=Nothing
Set Fso=Nothing
End Function

‘读取IP地址函数
Function ReadIpList(FileName)
Set Fso=Server.CreateObject(“Scripting.FileSystemObject”)
If Not Fso.FileExists(Server.MapPath(FileName)) Then
CreateFile(“Iplist.txt”)
Exit Function
End If

Set ts=Fso.OpenTextFile(Server.MapPath(FileName))
Iplist=ts.ReadAll
ts.Close
Set ts=Nothing
Set Fso=Nothing
ReadIpList=Iplist
End Function

‘创建文件函数
Function CreateFile(FileName)
Set Fso=Server.CreateObject(“Scripting.FileSystemObject”)
Set Cfs=Fso.CreateTextFile(Server.MapPath(FileName))
Cfs.Close
Set Cfs=Nothing
Set Fso=Nothing
End Function

‘关闭当前IE窗口函数(注:IE6下通过,其他浏览器未测试)
Function CloseWindow()
‘Response.Write “<script>window.location=’javascript:window.opener=null;window.close();'</script>”
Response.Redirect “http://www.baidu.com”
End Function

Ip=Request.ServerVariables(“REMOTE_ADDR”) ‘获取浏览者IP地址

Cookie=Request.Cookies(“IsBrow”) ‘获取当前Cookies
‘Response.Write Cookie

If Request.ServerVariables(“HTTP_X_FORWARDED_FOR”) <> “” Then
Response.Write “本站不允许使用代理访问”
Response.End()
Else
If Cookie=”Brow” Then
CloseWindow()
Else
If Instr(ReadIpList(“Iplist.txt”),Ip) <> 0 Then
CloseWindow()
Else
WriteIp “Iplist.txt” , Ip
End If
SetCookie()
End If
End If
%>

© 版权声明

相关文章