设置口令
cgi的一个有趣的特征是即使任何用户都能执行它们,但却没有办法在屏幕上显示她们。这意味着可以做一个口令脚本:
#********begin body**************
if ($value[0] ne "mypassword") {
print "invalid password";
} else {
print ’
<body bgcolor="white">
<h1> welcome, you have entered the<p>
password protected site </h1>
’;
};
#*********end body***************
要用这个脚本,需要建立一个有form的html页面。如果在form上只有password一个box,则在运行脚本时它传递给$value[0]。
和javascript不同,用户看不到源代码,所以使用以下代码是安全的:
if ($value[0] ne "mypassword") {
第一行为if语句,与在javascript中的用法相似。
在perl中,if语句不同,取决于是比较数字还是文本。比较数字,可以用==, !=, >, < 符号。如果比较文本,用eq判断是否相等,用ne判断是否不相等。
上面的语句确定在用户输入的文本不等于"mypassword"时将做什么。
print "invalid password";
口令不对时打印某些信息。
} else {
否则...
print ’
<body bgcolor="white">
<h1> welcome, you have entered the<p>
password protected site </h1>
’;
口令正确,进入有口令保护的网站。>>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器