ASP:Cookie使用指南(3)
来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-01 20:21 点击:次
这里有另外一个简单的例子:当访问者第1次浏览某个站点时,向他们显示欢迎信息。代码如下:
< %@ LANGUAGE="VBSCRIPT" % >
< %
RequestName = Request.Form("Name")
RequestLeaveMeAlone = Request.Form("LeaveMeAlone")
If RequestName < >"" or RequestLeaveMeAlone < >"" then
Response.Cookies("MySiteVisitorName") = RequestName
Response.Cookies("MySiteVisitorName").Expires = #January 01, 2010#
Response.Cookies("MySiteLeaveMeAlone") = RequestLeaveMeAlone
Response.Cookies("MySiteLeaveMeAlone").Expires = #January 01, 2010#
End if
VisitorName = request.cookies("MySiteVisitorName")
LeaveMeAlone = request.cookies("MySiteLeaveMeAlone")
If VisitorName ="" and LeaveMeAlone ="" then
% >
< HTML > < HEAD > < /HEAD >
< body bgcolor="#ccffff" text="black" link="navy" vlink="purple" >
< DIV ALIGN="CENTER" >
< form action="index.ASP" method="POST" >
< H2 >Let's be friends< /H2 >
What's your name (leave blank and hit the Submit button if you don't want us to know)?
< input type="text" name="name" >< BR >< BR >
< input type="hidden" name="LeaveMeAlone" value="x" >
< input type="submit" value="Submit" >
< /FORM >
< /DIV >
< /BODY >
< %
End if
If VisitorName < > "" then
Response.write "Hi, " & VisitorName & "! I hope you are having a great day!"
End if
'rest of the page
% >
好,现在来看看上面的代码实现执行了什么。首先,设置页面。然后,检查表单变量(在同一个页面中)。如果表单变量存在,就创建cookie,并设置到期时间。
< %@ LANGUAGE="VBSCRIPT" % >
< %
RequestName = Request.Form("Name")
RequestLeaveMeAlone = Request.Form("LeaveMeAlone")
If RequestName < >"" or RequestLeaveMeAlone < >"" then
Response.Cookies("MySiteVisitorName") = RequestName
Response.Cookies("MySiteVisitorName").Expires = #January 01, 2010#
Response.Cookies("MySiteLeaveMeAlone") = RequestLeaveMeAlone
Response.Cookies("MySiteLeaveMeAlone").Expires = #January 01, 2010#
End if
VisitorName = request.cookies("MySiteVisitorName")
LeaveMeAlone = request.cookies("MySiteLeaveMeAlone")
If VisitorName ="" and LeaveMeAlone ="" then
% >
< HTML > < HEAD > < /HEAD >
< body bgcolor="#ccffff" text="black" link="navy" vlink="purple" >
< DIV ALIGN="CENTER" >
< form action="index.ASP" method="POST" >
< H2 >Let's be friends< /H2 >
What's your name (leave blank and hit the Submit button if you don't want us to know)?
< input type="text" name="name" >< BR >< BR >
< input type="hidden" name="LeaveMeAlone" value="x" >
< input type="submit" value="Submit" >
< /FORM >
< /DIV >
< /BODY >
< %
End if
If VisitorName < > "" then
Response.write "Hi, " & VisitorName & "! I hope you are having a great day!"
End if
'rest of the page
% >
好,现在来看看上面的代码实现执行了什么。首先,设置页面。然后,检查表单变量(在同一个页面中)。如果表单变量存在,就创建cookie,并设置到期时间。
相关新闻>>
- 发表评论
-
- 最新评论 更多>>