正在阅读:ASP:Cookie使用指南ASP:Cookie使用指南

2005-07-11 10:02 出处: 作者:甘冀平翻译 责任编辑:moningfeng

   这里有另外一个简单的例子:当访问者第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,并设置到期时间。

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品