home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / MS_DEV / VID / SERVER / ASF / DATA.Z / global.asa < prev    next >
Text File  |  1996-10-22  |  3KB  |  97 lines

  1. <SCRIPT LANGUAGE=VBScript RUNAT=Server>
  2. SUB Application_OnStart
  3.     ' This script executes when a user first opens a page in an ActiveX application.
  4.     ' Open file and read the number of visitors so far
  5. Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
  6. Set Out= FileObject.OpenTextFile (Server.MapPath ("/AdvWorks") + "\visitors.txt", 1, FALSE, FALSE)
  7.  
  8.     ' Initialize soft visitor counter here
  9. application.lock
  10. application("visitors") = Out.ReadLine
  11. application.unlock
  12. END SUB
  13. </SCRIPT>
  14.  
  15.  
  16.  
  17. <SCRIPT LANGUAGE=VBScript RUNAT=Server>
  18. SUB Application_OnEnd
  19.  
  20.     ' This script executes when the server shuts down.
  21.  
  22.     ' Overwrites the existing visitors.txt file
  23. Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
  24. Set Out= FileObject.CreateTextFile (Server.MapPath ("/AdvWorks") + "\visitors.txt", TRUE, FALSE)
  25. Out.WriteLine(application("visitors"))
  26. END SUB
  27. </SCRIPT>
  28.  
  29.  
  30. <OBJECT RUNAT=Server SCOPE=Session ID=Conn PROGID="ADODB.Connection"></OBJECT>
  31.  
  32. <SCRIPT LANGUAGE=VBScript RUNAT=Server>
  33. SUB Session_OnStart
  34.     ' OnStart Event does four things:
  35.     ' 1) increment the visitor counter
  36.     ' 2) check for new or previous visitor to the site 
  37.     ' 3) create a connection to the database and store on the session object
  38.     ' 4) make sure the user does not jump into the middle of site -- redirect to default.asp if so
  39.     ' ----------------------------------
  40.  
  41.     ' Increase the visitor counter
  42. application.lock
  43. application("visitors")= application("visitors") + 1
  44. t_visitors = application("visitors")
  45. application.unlock
  46. Session("VisitorID") = t_visitors
  47.  
  48.     ' Periodically, save to file
  49. If t_visitors MOD 5 = 0 Then  
  50.     SET FileObject = Server.CreateObject("Scripting.FileSystemObject")
  51.     Set Out= FileObject.CreateTextFile (Server.MapPath ("/AdvWorks") + "\visitors.txt", TRUE, FALSE)
  52.     Out.WriteLine(t_visitors)
  53. End If
  54.  
  55.     ' Check to see if new client or been here before
  56.     ' If they've been here before, there will be a cookie called "CustomerID"
  57.     ' that is the primary key to the Customers table in the database
  58. CustomerID = Request.Cookies("CustomerID")
  59. If CustomerID = "" Then ' New visitor -- set special value which will prompt for user info later on
  60.   CustomerID = 0
  61. Else ' They've been here before -- get first name from the cookie for displaying later
  62.   Session("CustomerFirstName") = Request.Cookies("CustomerFirstName").Item
  63.   ' Put number of items ordered here
  64. End If
  65. Session("CustomerID") = CustomerID  ' Put on session for later use
  66.  
  67.     ' Open ADO Connection
  68. Conn.Open "AdvWorks", "advworks", "advworks"
  69.  
  70.     ' Create Shopping cart
  71. Dim ARYShoppingCart(9,5)
  72. Session("MyShoppingCart") = ARYShoppingCart
  73. Session("ItemCount") = 0
  74.  
  75.      ' Make sure that new users start on the correct
  76.     ' page of Adventure Works (default.asp)
  77. startPage = "/default.asp"
  78. currentPage = Request.ServerVariables("SCRIPT_NAME")
  79.  
  80.     ' Do a case insensitive compare, and if they
  81.     ' don't match, send the user to the start page.
  82. if strcomp(currentPage,startPage,1) then
  83. Response.Redirect("/AdvWorks" & startPage)
  84. end if
  85. END SUB
  86. </SCRIPT>
  87.  
  88.  
  89.  
  90.  
  91.  
  92. <SCRIPT LANGUAGE=VBScript RUNAT=Server>
  93.  SUB Session_OnEnd
  94.     ' Close database connection
  95.  Session("Conn").Close
  96.  END SUB
  97. </script>