Asp:Cookies应用指南,详细代码及教程(2)
2008-02-23 05:31:34来源:互联网 阅读 ()
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
接着,读取cookie:
VisitorName = request.cookies("MySiteVisitorName")
LeaveMeAlone = request.cookies("MySiteLeaveMeAlone")
如果cookie在访问者的计算机上不存在,就创建一个表单,询问相关信息:
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
如果cookie已经存在,并且用户名字存在,就显示给访问者一个欢迎界面,然后执行其余的代码。
If VisitorName < > "" then
Response.write "Hi, " & VisitorName & "! I hope you are having a great day!"
End if
'rest of the page
% >
尽管上面的这个例子很简单,但可以从中扩展许多富有创造力的应用。你可以在表单中加入许多功能,以便定制化web站点。
你还可以让访问者定制网站的色彩、字体,以至于其他web元素。有可能的话,你可以询问访问者的生日,当访问者在那一天来访
时,你就可以显示“生日快乐”的信息给他。
如你所见,cookie的扩展性是无穷的,这篇文章仅仅是抛砖引玉。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:asp事务处理
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
