当前位置:首页文章首页 IT学院 IT技术

关于使用Cookie来跟踪用户的实例

作者:  来源:  发布时间:2011-5-31 9:40:06  点击:

学习ASP程序设计的朋友可以进来看看,这是关于使用Cookie来跟踪用户的实例,希望对大家有所帮助。

Source Code:
  
  
  
  <%
  
  '*** Keeping track of how many times
  '*** a user visits a web page, by
  '*** reading and writing cookies.
  
  '*** In this example "asphole" will be
  '*** the name of our cookie, and
  '*** "totalvisit" will be the 'key'
  '*** value we keep track of. You can
  '*** have multiple 'keys' for each
  '*** cookie.
  
  '*** Declare your variables
  Dim NumVisit
  
  '*** Check to see how many times they
  '*** have been to your web page.
  NumVisit = Request.Cookies("asphole")("totalvisit")
  
  '*** If this is their first visit to
  '*** the page NumVisit is blank, so
  '*** make the value of NumVisit 0.
  If NumVisit = "" Then
  NumVisit = 0
  End If
  
  '*** Display how many times they have
  '*** visited your web page.
  Response.Write "Visits to this page: " & NumVisit
  
  '*** Count the visit to the web page
  NumVisit = NumVisit + 1
  
  '*** Write the new total back to
  '*** the cookie in their browser
  Response.Cookies("asphole")("totalvisit") = NumVisit
  
  '*** Specify when the cookie expires.
  '*** If you don't, the cookie will
  '*** expire when the user closes their
  '*** browser, and you'll lose all info.
  Response.Cookies("asphole").Expires = "January 1, 2020"
  
  %> 
  -END-

文章评论

软件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z