vallowens
asked on
Problem with ASP, global.asa, updating to Database
my website is my904.com when users log in it automatically set database table USERS= Online=true therefore showing them as online now as you can see if you go to the browse page, if they click the logout button it sets them Online=false, problem is if they hit the X button on browser they stay logged in forever or until i manually go in the database! keep in mind i picked up an ASP book 2 months ago and created this site from scratch i have no prior html or asp experience so please basic terms not to technical.
2nd: when users login in the session logs them out in about 5-10 minutes im enclosing a copy of my global.asa file. Please help, my investors are on my tail bout these 2 problems.
Should've went to school huh, not booksamillion!
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ------glob al.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'==FrontPage Generated - startspan==
Dim FrontPage_UrlVars(2)
'--Project Data Connection
Application("myspace_Conne ctionStrin g") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=********* /********* .mdb"
FrontPage_UrlVars(0) = "myspace_ConnectionString"
Application("myspace_Conne ctionTimeo ut") = 60
Application("myspace_Comma ndTimeout" ) = 30
Application("myspace_Curso rLocation" ) = 3
Application("myspace_Runti meUserName ") = ""
Application("myspace_Runti mePassword ") = ""
'--Project Data Connection
Application("myspaces_Conn ectionStri ng") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=********* **/******* **.mdb"
FrontPage_UrlVars(1) = "myspaces_ConnectionString "
Application("myspaces_Conn ectionTime out") = 60
Application("myspaces_Comm andTimeout ") = 30
Application("myspaces_Curs orLocation ") = 3
Application("myspaces_Runt imeUserNam e") = ""
Application("myspaces_Runt imePasswor d") = ""
'--
Application("FrontPage_Url Vars") = FrontPage_UrlVars
'==FrontPage Generated - endspan==
End Sub
Sub Session_OnStart
FrontPage_StartSession '==FrontPage Generated==
FrontPage_ConvertFromODBC '==FrontPage Generated==
End Sub
Sub FrontPage_StartSession
On Error Resume Next
if Len(Application("FrontPage _VRoot")) > 0 then Exit Sub
sFile = "global.asa"
sRootPath = Request.ServerVariables("A PPL_PHYSIC AL_PATH")
if Left(sRootPath,1) = "/" then sSep = "/" else sSep = "\"
if Right(sRootPath,1) <> sSep then sRootPath = sRootPath & sSep
sRootPath = sRootPath & sFile
' discover the VRoot for the current page;
' walk back up VPath until we match VRoot
Vroot = Request.ServerVariables("P ATH_INFO")
iCount = 0
do while Len(Vroot) > 1
idx = InStrRev(Vroot, "/")
if idx > 0 then
Vroot = Left(Vroot,idx)
else
' error; assume root web
Vroot = "/"
end if
if Server.MapPath(Vroot & sFile) = sRootPath then exit do
if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
iCount = iCount + 1
if iCount > 100 then
' error; assume root web
Vroot = "/"
exit do
end if
loop
' map all URL= attributes in _ConnectionString variables
Application.Lock
if Len(Application("FrontPage _VRoot")) = 0 then
Application("FrontPage_VRo ot") = Vroot
UrlVarArray = Application("FrontPage_Url Vars")
for i = 0 to UBound(UrlVarArray)
if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArr ay(i))
next
end if
Application.Unlock
End Sub
Sub FrontPage_MapUrl(AppVarNam e)
' convert URL attribute in conn string to absolute file location
strVal = Application(AppVarName)
strKey = "URL="
idxStart = InStr(strVal, strKey)
If idxStart = 0 Then Exit Sub
strBefore = Left(strVal, idxStart - 1)
idxStart = idxStart + Len(strKey)
idxEnd = InStr(idxStart, strVal, ";")
If idxEnd = 0 Then
strAfter = ""
strURL = Mid(strVal, idxStart)
Else
strAfter = ";" & Mid(strVal, idxEnd + 1)
strURL = Mid(strVal, idxStart, idxEnd - idxStart)
End If
strOut = strBefore & Server.MapPath(Application ("FrontPag e_VRoot") & strURL) & strAfter
Application(AppVarName) = strOut
End Sub
Sub FrontPage_ConvertFromODBC
On Error Resume Next
if Len(Application("ASP_OS")) > 0 then exit sub
str = "_ConnectionString"
slen = Len(str)
set oKnown = Server.CreateObject("Scrip ting.Dicti onary")
oKnown.Add "DRIVER",""
oKnown.Add "DBQ",""
oKnown.Add "SERVER",""
oKnown.Add "DATABASE",""
oKnown.Add "UID",""
oKnown.Add "PWD",""
Application.Lock
For each item in Application.Contents
if UCase(Right(item,slen)) = UCase(str) then
sName = Left(item,Len(item)-slen)
sConn = Application(item)
if InStr(LCase(sConn),"provid er=") < 1 and Len(Application(sName & "_ConnectionTimeout"))>0 then
sArr = Split(sConn,";")
set oDict = Server.CreateObject("Scrip ting.Dicti onary")
bUnknown = False
for i = 0 to UBound(sArr)
s = sArr(i)
idx = InStr(s,"=")
sKey = UCase(Trim(Left(s,idx-1)))
sVal = Trim(Mid(s,idx+1))
oDict.Add sKey, sVal
if Not oKnown.Exists(sKey) then bUnknown = True
next
if bUnknown = False and oDict.Exists("DRIVER") then
sDrv = oDict.Item("DRIVER")
sNew = ""
if InStr(sDrv,"Microsoft Access") > 0 and oDict.Exists("DBQ") and not (oDict.Exists("UID") or oDict.Exists("PWD")) then
sNew = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" & oDict.Item("DBQ")
elseif InStr(sDrv,"SQL Server") > 0 and oDict.Exists("SERVER") and oDict.Exists("DATABASE") then
sNew = "Provider=SQLOLEDB;Data Source=" & oDict("SERVER") & ";Initial Catalog=" & oDict("DATABASE")
if oDict.Exists("UID") then sNew = sNew & ";User ID=" & oDict("UID")
if oDict.Exists("PWD") then sNew = sNew & ";Password=" & oDict("PWD")
end if
if sNew <> "" then
Application(item) = sNew
end if
end if
set oDict = Nothing
end if
end if
Next
Application.Unlock
Set oKnown = Nothing
End Sub
</SCRIPT>
<head><title>Web Site Settings for Active Server Pages</title><html xmlns:mso="urn:schemas-mic rosoft-com :office:of fice" xmlns:msdt="uuid:C2F41010- 65B3-11d1- A29F-00AA0 0C14882">
<!--[if gte mso 9]><xml>
<mso:CustomDocumentPropert ies>
<mso:connectionstatus msdt:dt="string">myspace=1 </mso:conn ectionstat us>
</mso:CustomDocumentProper ties>
</xml><![endif]-->
</head>
2nd: when users login in the session logs them out in about 5-10 minutes im enclosing a copy of my global.asa file. Please help, my investors are on my tail bout these 2 problems.
Should've went to school huh, not booksamillion!
--------------------------
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'==FrontPage Generated - startspan==
Dim FrontPage_UrlVars(2)
'--Project Data Connection
Application("myspace_Conne
FrontPage_UrlVars(0) = "myspace_ConnectionString"
Application("myspace_Conne
Application("myspace_Comma
Application("myspace_Curso
Application("myspace_Runti
Application("myspace_Runti
'--Project Data Connection
Application("myspaces_Conn
FrontPage_UrlVars(1) = "myspaces_ConnectionString
Application("myspaces_Conn
Application("myspaces_Comm
Application("myspaces_Curs
Application("myspaces_Runt
Application("myspaces_Runt
'--
Application("FrontPage_Url
'==FrontPage Generated - endspan==
End Sub
Sub Session_OnStart
FrontPage_StartSession '==FrontPage Generated==
FrontPage_ConvertFromODBC '==FrontPage Generated==
End Sub
Sub FrontPage_StartSession
On Error Resume Next
if Len(Application("FrontPage
sFile = "global.asa"
sRootPath = Request.ServerVariables("A
if Left(sRootPath,1) = "/" then sSep = "/" else sSep = "\"
if Right(sRootPath,1) <> sSep then sRootPath = sRootPath & sSep
sRootPath = sRootPath & sFile
' discover the VRoot for the current page;
' walk back up VPath until we match VRoot
Vroot = Request.ServerVariables("P
iCount = 0
do while Len(Vroot) > 1
idx = InStrRev(Vroot, "/")
if idx > 0 then
Vroot = Left(Vroot,idx)
else
' error; assume root web
Vroot = "/"
end if
if Server.MapPath(Vroot & sFile) = sRootPath then exit do
if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
iCount = iCount + 1
if iCount > 100 then
' error; assume root web
Vroot = "/"
exit do
end if
loop
' map all URL= attributes in _ConnectionString variables
Application.Lock
if Len(Application("FrontPage
Application("FrontPage_VRo
UrlVarArray = Application("FrontPage_Url
for i = 0 to UBound(UrlVarArray)
if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArr
next
end if
Application.Unlock
End Sub
Sub FrontPage_MapUrl(AppVarNam
' convert URL attribute in conn string to absolute file location
strVal = Application(AppVarName)
strKey = "URL="
idxStart = InStr(strVal, strKey)
If idxStart = 0 Then Exit Sub
strBefore = Left(strVal, idxStart - 1)
idxStart = idxStart + Len(strKey)
idxEnd = InStr(idxStart, strVal, ";")
If idxEnd = 0 Then
strAfter = ""
strURL = Mid(strVal, idxStart)
Else
strAfter = ";" & Mid(strVal, idxEnd + 1)
strURL = Mid(strVal, idxStart, idxEnd - idxStart)
End If
strOut = strBefore & Server.MapPath(Application
Application(AppVarName) = strOut
End Sub
Sub FrontPage_ConvertFromODBC
On Error Resume Next
if Len(Application("ASP_OS"))
str = "_ConnectionString"
slen = Len(str)
set oKnown = Server.CreateObject("Scrip
oKnown.Add "DRIVER",""
oKnown.Add "DBQ",""
oKnown.Add "SERVER",""
oKnown.Add "DATABASE",""
oKnown.Add "UID",""
oKnown.Add "PWD",""
Application.Lock
For each item in Application.Contents
if UCase(Right(item,slen)) = UCase(str) then
sName = Left(item,Len(item)-slen)
sConn = Application(item)
if InStr(LCase(sConn),"provid
sArr = Split(sConn,";")
set oDict = Server.CreateObject("Scrip
bUnknown = False
for i = 0 to UBound(sArr)
s = sArr(i)
idx = InStr(s,"=")
sKey = UCase(Trim(Left(s,idx-1)))
sVal = Trim(Mid(s,idx+1))
oDict.Add sKey, sVal
if Not oKnown.Exists(sKey) then bUnknown = True
next
if bUnknown = False and oDict.Exists("DRIVER") then
sDrv = oDict.Item("DRIVER")
sNew = ""
if InStr(sDrv,"Microsoft Access") > 0 and oDict.Exists("DBQ") and not (oDict.Exists("UID") or oDict.Exists("PWD")) then
sNew = "Provider=Microsoft.Jet.OL
elseif InStr(sDrv,"SQL Server") > 0 and oDict.Exists("SERVER") and oDict.Exists("DATABASE") then
sNew = "Provider=SQLOLEDB;Data Source=" & oDict("SERVER") & ";Initial Catalog=" & oDict("DATABASE")
if oDict.Exists("UID") then sNew = sNew & ";User ID=" & oDict("UID")
if oDict.Exists("PWD") then sNew = sNew & ";Password=" & oDict("PWD")
end if
if sNew <> "" then
Application(item) = sNew
end if
end if
set oDict = Nothing
end if
end if
Next
Application.Unlock
Set oKnown = Nothing
End Sub
</SCRIPT>
<head><title>Web Site Settings for Active Server Pages</title><html xmlns:mso="urn:schemas-mic
<!--[if gte mso 9]><xml>
<mso:CustomDocumentPropert
<mso:connectionstatus msdt:dt="string">myspace=1
</mso:CustomDocumentProper
</xml><![endif]-->
</head>
ASKER
Ive tried the onUnload feature but i need the the unOnload to only work when the users click the X on the browser not switch to another page or hit refresh! I know it can be done because when ya get certain popups when ya hit X they redirect you to another page
Yes, but I thought they used tthe onUnLoad function for that
I didnt realise refresh causes that
With regards to switching to another page, what about this
create a variable in your javascript, say call it exitFlag
initialise to 1
Now instead of using A HREF, call a javascript function which sets exitFlag to 0 then loads your new page
On the unload event, check exitFlag, if 1, then u know they are exiting, if 0 then they have clicked a link
I didnt realise refresh causes that
With regards to switching to another page, what about this
create a variable in your javascript, say call it exitFlag
initialise to 1
Now instead of using A HREF, call a javascript function which sets exitFlag to 0 then loads your new page
On the unload event, check exitFlag, if 1, then u know they are exiting, if 0 then they have clicked a link
ASKER
cool is it anyway u can giv me an example of this? it would be much appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use the onUnLoad function to capture a window closure,
Alternative is on your site, you have your home page, which pops up a new window, this new window has no close button/no toolbar etc
And u access your site thru that