网络编程
位置:首页>> 网络编程>> Asp编程>> 如何决定是否将登录内容保存到Cookie里?

如何决定是否将登录内容保存到Cookie里?

 来源:asp之家 发布时间:2009-12-16 18:54:00 

标签:cookie,保存,登录,asp

很简单,我们用两个文件就可以实现这一功能:

login.htm

<% @ Language=JavaScript %>
<%
if (Request.Cookies("SavedLogin").HasKeys) {
    Response.Redirect("checklogin.asp?cookie=1")
}
%>
<HTML>
<HEAD>
<TITLE>登录页面 - asp之家</TITLE>
</HEAD>
<BODY>
我要登录Aspxhome.com
<FORM ACTION="CheckLogin.asp" METHOD="POST">
    电子邮件: <INPUT TYPE="Text" NAME="email" SIZE="40"><BR>
    口令: <INPUT TYPE="Password" NAME="Password" SIZE="40"><P>
    <INPUT TYPE="Checkbox" NAME="SaveLogin"> 要把登录内容存为Cookie吗?<P>
    <INPUT TYPE="Submit" VALUE="登录"><INPUT TYPE="RESET">
</FORM>

checklogin.asp

<%
dim strEmail
if Request.QueryString("cookie") = 1 then
    strEMail = Request.Cookies("SavedLogin")("Email")
else
    strEMail = Request.Form("email")
end if
dim bLoginSaved
if Request.Form("SaveLogin") = "on" then
    Response.Cookies("SavedLogin")("EMail") = Request("email")
    Response.Cookies("SavedLogin")("pw") = Request("password")
    Response.Cookies("SavedLogin").Expires = Date + 30
    bLoginSaved = True
else
    bLoginSaved = False
end if
%>
<HTML>
<HEAD>
<TITLE>登录验证 - asp之家</TITLE>
</HEAD>
<BODY>
<% if bLoginSaved then %>
    将登录信息保存到Cookie里去<HR>
<% end if %>
欢迎光临Aspxhome.com!<P>
<% if Request.QueryString("cookie") = 1 then %>
    保存成功!<P>
<% end if %>
请确认您的电子邮件: <% = strEMail %>
</BODY>
</HTML>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com