限制一個ip只能訪問一次,現在將asp程式碼分享給大家:
原理:當用戶第一次訪問的時候,得到使用者的IP,然後把IP存到中去。下次再訪問的時候,先去中查詢他的'IP是否存在,正在的話就不允許訪問
<%
'/////////////////////////////////////////////////////
'// //
'//作用:一個IP地址只允許訪問本頁一次 //
'//引用: //
'// //
'/////////////////////////////////////////////////////
'er = false '關閉緩衝區
Dim Fso,ts,IpList,Cfs
'設定Cookies函式
Function SetCookie()
ies("IsBrow") = "Brow"
ies("IsBrow")res = Date+365
End Function
'記錄IP地址函式
Function WriteIp(FileName, IpAddress)
Set Fso = teObject("SystemObject")
Set ts = Fso.OpenTextFile(Server.MapPath(FileName),8,true)
eLine IpAddress
e
Set ts = Nothing
Set Fso = Nothing
End Function
'讀取IP地址函式
Function ReadIpList(FileName)
Set Fso = teObject("SystemObject")
If Not Fso.FileExists(Server.MapPath(FileName)) Then
CreateFile("")
Exit Function
End If
Set ts = Fso.OpenTextFile(Server.MapPath(FileName))
Iplist = All
e
Set ts = Nothing
Set Fso = Nothing
ReadIpList = Iplist
End Function
'建立檔案函式
Function CreateFile(FileName)
Set Fso = teObject("SystemObject")
Set Cfs = Fso.CreateTextFile(Server.MapPath(FileName))
e
Set Cfs = Nothing
Set Fso = Nothing
End Function
'關閉當前IE視窗函式(注:IE6下通過,其他瀏覽器未測試)
Function CloseWindow()
'e ""
rect ""
End Function
Ip = erVariables("REMOTE_ADDR") '獲取瀏覽者IP地址
Cookie = ies("IsBrow") '獲取當前Cookies
'e Cookie
If erVariables("HTTP_X_FORWARDED_FOR") <> "" Then
e "本站不允許使用代理訪問"
()
Else
If Cookie = "Brow" Then
CloseWindow()
Else
If Instr(ReadIpList(""),Ip) <> 0 Then
CloseWindow()
Else
WriteIp "" , Ip
End If
SetCookie()
End If
End If
%>