标题:
Cookie与PERL
[打印本页]
作者:
cnangel
时间:
2005-8-25 19:48
标题:
Cookie与PERL
作者:小歪歪
日期:2001-1-12 16:45:38
#!/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();
documents.cookie = name + "=" + escape(value) + expString;
}
// returns value of cookie or null if cookie does not exist
function GetCookie(name)
{
var result = null;
var myCookie = " " + documents.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
复制代码
——————以下内容由
Cnangel
在
2005年08月25日 07:49pm
时添加———————
这个Cookie的方式并不是很详细,等我把一个Cookie的问题彻底解决了,哪天来补充一下.
欢迎光临 星星博客 (http://fans.huhoo.net/)
Powered by Discuz! 7.0.0