aspは1つのipが1回しかアクセスできないことを制限する方法を実現する

2515 ワード

1つのipに1回しかアクセスできないことを制限し、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 "window.location='javascript:window.opener=null;window.close();'" 
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 
%>

以上、皆さんに共有したasp実装コードですが、皆さんの勉強に役立つことを願っています.