限制一个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+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
%> 【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!