Limit the ASP code that one IP can access only once

Source: Internet
Author: User
Tags servervariables setcookie

Limit an IP access only once, reproduced in the BACDE technology blog, now the ASP code to share to everyone:

<%


'///////////////////////////////////////////////////// 


'// // 


'//function: One IP address is only allowed to access this page once//


'//Author: bacde March 1, 2010 //


'//reference:<!--#include file= "check_ip.asp"-->//


'// // 


'///////////////////////////////////////////////////// 





' Response.Charset = 936 ' Set output encoding to Simplified Chinese


' Response.Buffer = False ' closes buffer





Dim fso,ts,iplist,cfs





' Set cookies function


Function Setcookie ()


response.cookies ("isbrow") = "Brow"


response.cookies ("Isbrow"). Expires = date+365


End Function





' record IP address function


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





' read IP address function


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





' Create a file 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





' Closes the current IE window function (Note: IE6 is passed, other browsers are not tested)


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") ' Get browser IP address





cookies = request.cookies ("Isbrow") ' Get current cookies


' Response.Write Cookie





If request.servervariables ("http_x_forwarded_for") <> "" Then


Response.Write "This site is not allowed to use proxy access"


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


%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.