欢迎光临
我们一直在努力

例子(请多多指教)-CGI教程,CGI文档

建站超值云服务器,限时71元/月

#!/usr/bin/perl -w
让用户输入用户名和密码

use strict;
use cgi;

#检查用户名和密码开始
my $mycgi=new cgi;

print <<headpart;
content-type:text/html

<html><head><title>test it :)</title>
<meta http-equiv=content-type content=text/html; charset=gb2312>
<script language="javascript">
<!–
var never = new date()
never.settime(never.gettime() + 2000*24*60*60*1000);

function setcookie(name, value)
{
    var expstring = "; expires=" + never.togmtstring();
    document.cookie = name + "=" + escape(value) + expstring;
}

// returns value of cookie or null if cookie does not exist
function getcookie(name)
{
    var result = null;
    var mycookie = " " + document.cookie + ";";
    var searchname = " " + name + "=";
    var startofcookie = mycookie.indexof(searchname);
    var endofcookie;
    if (startofcookie != -1)
    {
        startofcookie += searchname.length; // skip past name of cookie
        endofcookie = mycookie.indexof(";", startofcookie);
        result = unescape(mycookie.substring(startofcookie, endofcookie));
    }
    return result;
}
function gogo()
{
    setcookie(username,document.form1.username.value);
    setcookie(password,document.form1.password.value);
    document.form1.submit();
}
// –>
</script>
</head>

<body bgcolor="#ffffff">

<form name=form1 method=post action=/***/other.pl enctype=multipart/form-data>
  <p>用户名:
    
<script language=javascript>
<!–
    var username=getcookie("username");
    if (username==null)
    {
        document.write (<input type=text name=username class=p1>);
    }
    if (username !== null)
    {
        document.write ("<input type=text name=username value="+username+" class=p1>");
    }
    document.write ("<br>密 码: ");
    var password=getcookie("password");
    if (password==null)
    {
        document.write (<input type=password name=password class=p1>);
    }
    if (password !== null)
    {
        document.write ("<input type=password name=password value="+password+" class=p1>");
    }
// –>
</script>

    <br><br>
    <input type=hidden name=pageid value="$pageid">
  </p>
headpart

print <<theend;
<input type="button" name="submit" value="进 入" onclick="gogo();"><br>
</form>
* 现已加入cookie,只需要第一次输入用户名和密码,以后系统即可自动记录,不用再输了
</body>
</html>
theend

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 例子(请多多指教)-CGI教程,CGI文档
分享到: 更多 (0)