This article mainly introduces the method of limiting an IP access to a single time asp implementation. Interested friends can refer to it.
Restricting an IP to access only once, now I will share the asp code with you:
- <%
- '///////////////////////////////////////////////////////////////////////// /////
- '////
- '//Function: One IP address only allows access to this page once//
- '//Quote: <!--#includefile=Check_Ip.asp-->//
- '////
- '///////////////////////////////////////////////////////////////////////// /////
- 'Response.Charset=936' Set the output encoding to Simplified Chinese
- 'Response.Buffer=false' Close the buffer
- DimFso,ts,IpList,Cfs
- 'Set the Cookies function
- FunctionSetCookie()
- Response.Cookies(IsBrow)=Brow
- Response.Cookies(IsBrow).Expires=Date+365
- EndFunction
- 'Record IP address function
- FunctionWriteIp(FileName,IpAddress)
- SetFso=Server.CreateObject(Scripting.FileSystemObject)
- Setts=Fso.OpenTextFile(Server.MapPath(FileName),8,true)
- ts.WriteLineIpAddress
- ts.Close
- Setts=Nothing
- SetFso=Nothing
- EndFunction
- 'Read IP address function
- FunctionReadIpList(FileName)
- SetFso=Server.CreateObject(Scripting.FileSystemObject)
- IfNotFso.FileExists(Server.MapPath(FileName)) Then
- CreateFile(Iplist.txt)
- ExitFunction
- EndIf
- Setts=Fso.OpenTextFile(Server.MapPath(FileName))
- Iplist=ts.ReadAll
- ts.Close
- Setts=Nothing
- SetFso=Nothing
- ReadIpList=Iplist
- EndFunction
- 'Create a file function
- FunctionCreateFile(FileName)
- SetFso=Server.CreateObject(Scripting.FileSystemObject)
- SetCfs=Fso.CreateTextFile(Server.MapPath(FileName))
- Cfs.Close
- SetCfs=Nothing
- SetFso=Nothing
- EndFunction
- 'Close the current IE window function (Note: passed under IE6, other browsers have not tested it)
- FunctionCloseWindow()
- 'Response.Write<script>window.location='javascript:window.opener=null;window.close();'</script>
- Response.Redirectthttp://www.baidu.com
- EndFunction
- Ip=Request.ServerVariables(REMOTE_ADDR)'Get the viewer's IP address
- Cookie=Request.Cookies(IsBrow)'Get the current cookies
- 'Response.WriteCookie
- IfRequest.ServerVariables(HTTP_X_FORWARDED_FOR)<>Then
- Response.Write This site does not allow proxy access
- Response.End()
- Else
- IfCookie=BrowThen
- CloseWindow()
- Else
- IfInstr(ReadIpList(Iplist.txt),Ip)<>0Then
- CloseWindow()
- Else
- WriteIpIplist.txt,Ip
- EndIf
- SetCookie()
- EndIf
- EndIf
- %>
The above is the asp implementation code shared with you, I hope it will be helpful to your learning.