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 >
Wrap
Text File
|
1996-10-22
|
3KB
|
97 lines
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Application_OnStart
' This script executes when a user first opens a page in an ActiveX application.
' Open file and read the number of visitors so far
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
Set Out= FileObject.OpenTextFile (Server.MapPath ("/AdvWorks") + "\visitors.txt", 1, FALSE, FALSE)
' Initialize soft visitor counter here
application.lock
application("visitors") = Out.ReadLine
application.unlock
END SUB
</SCRIPT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Application_OnEnd
' This script executes when the server shuts down.
' Overwrites the existing visitors.txt file
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
Set Out= FileObject.CreateTextFile (Server.MapPath ("/AdvWorks") + "\visitors.txt", TRUE, FALSE)
Out.WriteLine(application("visitors"))
END SUB
</SCRIPT>
<OBJECT RUNAT=Server SCOPE=Session ID=Conn PROGID="ADODB.Connection"></OBJECT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Session_OnStart
' OnStart Event does four things:
' 1) increment the visitor counter
' 2) check for new or previous visitor to the site
' 3) create a connection to the database and store on the session object
' 4) make sure the user does not jump into the middle of site -- redirect to default.asp if so
' ----------------------------------
' Increase the visitor counter
application.lock
application("visitors")= application("visitors") + 1
t_visitors = application("visitors")
application.unlock
Session("VisitorID") = t_visitors
' Periodically, save to file
If t_visitors MOD 5 = 0 Then
SET FileObject = Server.CreateObject("Scripting.FileSystemObject")
Set Out= FileObject.CreateTextFile (Server.MapPath ("/AdvWorks") + "\visitors.txt", TRUE, FALSE)
Out.WriteLine(t_visitors)
End If
' Check to see if new client or been here before
' If they've been here before, there will be a cookie called "CustomerID"
' that is the primary key to the Customers table in the database
CustomerID = Request.Cookies("CustomerID")
If CustomerID = "" Then ' New visitor -- set special value which will prompt for user info later on
CustomerID = 0
Else ' They've been here before -- get first name from the cookie for displaying later
Session("CustomerFirstName") = Request.Cookies("CustomerFirstName").Item
' Put number of items ordered here
End If
Session("CustomerID") = CustomerID ' Put on session for later use
' Open ADO Connection
Conn.Open "AdvWorks", "advworks", "advworks"
' Create Shopping cart
Dim ARYShoppingCart(9,5)
Session("MyShoppingCart") = ARYShoppingCart
Session("ItemCount") = 0
' Make sure that new users start on the correct
' page of Adventure Works (default.asp)
startPage = "/default.asp"
currentPage = Request.ServerVariables("SCRIPT_NAME")
' Do a case insensitive compare, and if they
' don't match, send the user to the start page.
if strcomp(currentPage,startPage,1) then
Response.Redirect("/AdvWorks" & startPage)
end if
END SUB
</SCRIPT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Session_OnEnd
' Close database connection
Session("Conn").Close
END SUB
</script>