ASP编程入门进阶(六):Cookies讲座(3)




<%
For each cookie in Request.Cookies
if Request.cookies(cookie).HasKeys =false then
Response.write cookie & "=" & Request.Cookies(cookie)
Response.write ("<br>")
Else
for each key in Request.Cookies(cookie)
Response.write ("<font color=blue>")
Response.write cookie & ".("&key&")" & "=" & Request.Cookies(cookie)(key)
Response.write ("</font><br>")
next
end if
next
%>



◆ check.asp
'首先,设置页面。然后,检查表单变量(在同一个页面中)。如果表单变量存在,就创建cookie,并设置到期时间。


<%@ LANGUAGE="VBSCRIPT" %>
<%
bgcolor = Request.Form("bgcolor")
fgcolor = Request.Form("fgcolor")
pwd = Request.form("pwd")

If bgcolor <>"" or fgcolor <>"" then
Response.cookies("check")("bgcolor") = bgcolor
Response.Cookies("check")("fgcolor") = fgcolor
Response.Cookies("check")("pwd") = pwd
Response.Cookies("check").Expires=#may 01, 2004#
End if
'接着,读取cookie
bgcolor = request.cookies("check")("bgcolor")
fgcolor = request.cookies("check")("fgcolor")
pwd = request.cookies("check")("pwd")
'如果cookie在访问者的计算机上不存在,就创建一个表单,询问相关信息
If bgcolor ="" and fgcolor ="" and pwd="" then
%>
<HTML>
<HEAD> </HEAD>
<body>
<DIV ALIGN="CENTER" >
<Form action="check.asp" method="POST">
Bgcolor: <input type="text" name="bgcolor"><BR>
Fgcolor: <input type="text" name="fgcolor"><BR>
Password:<input type="password" name="pwd"><BR>
<input type="submit" value="Submit">
</Form>
</DIV>
</BODY>
<%
End if
'如果cookie已经存在,并且bgcolor存在,就跳转到color.asp。
If bgcolor <> "" then
Response.Redirect "color.asp"
End if
%>



◆ color.asp(显示用户爱好颜色的页面特性)


<%
bgcolor=request.cookies("check")("bgcolor")
fgcolor=request.cookies("check")("fgcolor")
pwd=request.cookies("check")("pwd")
%>
<%response.write("<body bgcolor="&bgcolor&"><font color="&fgcolor&">")%>
你的密码是:
<%response.write(" "&pwd&" ")%>


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3087.html