推荐:关于学习ASP和编程的28个观点1.不要放过任何一个看上去很简单的小编程问题-他们往往并不那么简单,或者可以引伸出很多知识点;2.会用asp,并不说明你会asp; 3.看asp的书,是学不了asp语言的; 4.
要使用request对象的ServerVariables属性,通过它来获得环境变量的值。使用的语法为:Request.ServerVariables(variable),variable表示环境变量的名称,如服务器主机名称、Web服务器软件名等等,若variable为REMOTE_ADDR则表示访问者的IP地址,通过它就可以实现IP地址的过滤。
源程序如下:(文件名:demo.ASP)
| 以下为引用的内容: <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页面防火墙功能演示</title> </head> <body background=back.jpg> <% ′使用Request.ServerVariables(REMOTE_ADDR)得到IP地址并保存在变量rip中 rip=Request.ServerVariables(REMOTE_ADDR) strip=cstr(rip) ′取得IP地址第三个段的值并保存到strip中 for i=1 to 2 strip=right(strip,len(strip)-instr(1,strip,.)) next strip=left(strip,instr(1,strip,.)-1) ′IP地址有效性检验及密码验证,包括两方面的内容: ′如果IP地址符合则通过验证;如果IP地址不符合则检验输入的密码是否正确(此处密码为asp) if (left(rip,5) <> 127.1 or strip<1 or strip>50) and request(Passwd)<>asp then %> <p><font color=#FF0000>对不起,你的IP是<%=rip%>,本页面可以访问的IP是127.1.1.*到127.1.50.*之间,如果你是本单位内部网的用户,请确认你的浏览器没有使用代理!<BR></font></p> <form action=demo.asp method=POST id=form1 name=form1> <p>请输入访问密码:<input type=password name=Passwd > <input type=submit value=确认 name=B1>; </p> </form> <%else %> ′合法用户可以访问的页面,在此可以加入任何信息 祝贺您,您已经顺利通过了页面的安全认证,可以直接使用本站点的资源! <%end if%> </body> </html> |
实际使用只要稍微修改上面的程序(如IP地址等信息)就可以了,当然这只是在一个页面中实现了安全防范功能,如果一个网站有多个页面的话,可以设置一个session变量来对用户进行标志,以在后面的页面中进行判断。
分享:ADO初学者教程:ADO 通过GetString()加速脚本作者:请使用GetString()方法来加速您的ASP脚本(来代替多行的Response.Write)。实例使用 GetString()如何使用GetString()在HTML表格中显示记录集中的数据。多行Response.Write