源码
资讯
  当前位置:源码网网络学院网络编程PHP教程 → ASP:Cookie使用指南(4)
特别推荐
热点TOP10
本周下载排行
本月下载排行
ASP:Cookie使用指南(4)
日期:2006年2月26日 作者: 人气: 查看: [大字体 中字体 小字体]
    < %@ 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的扩展性是无穷的,这篇文章仅仅是抛砖引玉。

(出处:源码网)

百度搜索 Google搜索 雅虎搜索 我要投稿
相关文章: 相关软件: