DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   asp (http://www.daniweb.com/code/asp.html)
-   -   Blocking an IP adress to a certain page (http://www.daniweb.com/code/snippet421.html)

msaqib asp syntax
Nov 6th, 2005
This is a small function that will block the specific IP from viewing the certain page, and it will redirect the user to the main page or noaccess page.

  1. <%
  2. '''''''''''''''''''''''''''''''
  3. ' Block the IP addresses that do the SPAM
  4. '''''''''''''''''''''''''''''''
  5. Function IsBlockedIP()
  6. Dim UserIP
  7. Dim BlockedIParray(2)
  8. 'assign our blocked IP addresses to our array
  9. BlockedIParray(0) = "60.0.201.209"
  10. BlockedIParray(1) = "218.11.15.212"
  11. 'retrieve the visitors IP address
  12. UserIP = Request.ServerVariables("REMOTE_ADDR")
  13.  
  14. 'loop through the Blocked IPs
  15. For i = 0 to UBound(BlockedIParray)
  16. If UserIP = BlockedIParray(i) Then
  17. Response.Redirect "index.asp"
  18. 'Response.Redirect "noaccess.asp"
  19.  
  20. End If
  21. Next
  22. End Function
  23. %>