Recommended: 28 views on learning ASP and programming 1. Don’t miss any small programming problem that seems simple - they are often not that simple, or can lead to a lot of knowledge points; 2. Being able to use asp does not mean that you can do asp; 3. You can’t learn the asp language by reading asp books; 4.
To use the ServerVariables property of the request object, use it to get the value of the environment variable. The syntax used is: Request.ServerVariables(variable), variable represents the name of the environment variable, such as the server host name, the web server software name, etc. If the variable is REMOTE_ADDR, it represents the visitor's IP address, and through it, the IP address filtering can be achieved.
The source program is as follows: (File name: demo.ASP)
| The following is the quoted content: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=gb_2312-80> <meta name=GENERATOR content=Microsoft FrontPage Express 2.0> <style> <!- .as{ line-height: 15px; font-size: 9pt } a:hover {color: rgb(0,51,240);text-decoration:underline} .p9 { font-family: 安体; font-size: 9pt; line-height: 15pt} .p12 { font-family: 安体; font-size: 12pt; line-height: 18pt} a:link { text-decoration: none;} a: visited { text-decoration:none;} a:hover {text-decoration: underline;font-size: 125%;color:blue} -> </style> <title>ASP page firewall function demonstration</title> </head> <body background=back.jpg> <% ′ Use Request.ServerVariables(REMOTE_ADDR) to get the IP address and save it in the variable rip rip=Request.ServerVariables(REMOTE_ADDR) strip=cstr(rip) ′ Get the value of the third segment of the IP address and save it to strip for i=1 to 2 strip=right(strip,len(strip)-instr(1,strip,.))) next strip=left(str,instr(1,str,.)-1) ′IP address validity verification and password verification, including two aspects: 'If the IP address is in compliance, pass verification; if the IP address does not conform, check whether the entered password is correct (here the password is asp) if (left(rip,5) <> 127.1 or strip<1 or strip>50) and request(Passwd)<>asp then %> <p<font color=#FF0000> Sorry, your IP is <%=rip%>, and the IPs that can be accessed on this page are between 127.1.1.* and 127.1.50.*. If you are a user of the internal network of this unit, please make sure that your browser does not use a proxy! <BR></font> <form action=demo.asp method=POST id=form1 name=form1> <p> Please enter the access password: <input type=password name=Passwd > <input type=submit value=confirm name=B1>; </p> </form> <%else %> ′A page that legal users can access, any information can be added here Congratulations, you have successfully passed the page security certification and can directly use the resources of this site! <%end if %> </body> </html> |
In fact, just slightly modify the above program (such as IP address and other information). Of course, this only implements security prevention functions in one page. If a website has multiple pages, you can set a session variable to mark the user to make judgments in the subsequent page.
Share: ADO beginner tutorial: ADO accelerates scripts with GetString() Author: Please use the GetString() method to speed up your ASP script (instead of multi-line Response.Write). Instance using GetString() How to use GetString() to display data in a record set in an HTML table. Multi-line Response.Write