Source Code:
1
2
3'*** Keeping track of how many times
4'*** a user visits a web page, by
5'*** reading and writing cookies.
6
7'*** In this example "asphole" will be
8'*** the name of our cookie, and
9'*** "totalvisit" will be the 'key'
10'*** value we keep track of. You can
11'*** have multiple 'keys' for each
12'*** cookie.
13
14'*** Declare your variables
15Dim NumVisit
16
17'*** Check to see how many times they
18'*** have been to your web page.
19NumVisit = Request.Cookies("asphole")("totalvisit")
20
21'*** If this is their first visit to
22'*** the page NumVisit is blank, so
23'*** make the value of NumVisit 0.
24If NumVisit = "" Then
25NumVisit = 0
26End If
27
28'*** Display how many times they have
29'*** visited your web page.
30Response.Write "Visits to this page: " & NumVisit
31
32'*** Count the visit to the web page
33NumVisit = NumVisit + 1
34
35'*** Write the new total back to
36'*** the cookie in their browser
37Response.Cookies("asphole")("totalvisit") = NumVisit
38
39'*** Specify when the cookie expires.
40'*** If you don't, the cookie will
41'*** expire when the user closes their
42'*** browser, and you'll lose all info.
43Response.Cookies("asphole").Expires = "January 1, 2020"
44
-END-