Link to home
Start Free TrialLog in
Avatar of vallowens
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!

--------------------------------------------------------------------------------------------global.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
     '==FrontPage Generated - startspan==
     Dim FrontPage_UrlVars(2)
     '--Project Data Connection
          Application("myspace_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=*********/*********.mdb"
          FrontPage_UrlVars(0) = "myspace_ConnectionString"
          Application("myspace_ConnectionTimeout") = 60
          Application("myspace_CommandTimeout") = 30
          Application("myspace_CursorLocation") = 3
          Application("myspace_RuntimeUserName") = ""
          Application("myspace_RuntimePassword") = ""
     '--Project Data Connection
          Application("myspaces_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=***********/*********.mdb"
          FrontPage_UrlVars(1) = "myspaces_ConnectionString"
          Application("myspaces_ConnectionTimeout") = 60
          Application("myspaces_CommandTimeout") = 30
          Application("myspaces_CursorLocation") = 3
          Application("myspaces_RuntimeUserName") = ""
          Application("myspaces_RuntimePassword") = ""
     '--
     Application("FrontPage_UrlVars") = 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("APPL_PHYSICAL_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("PATH_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_VRoot") = Vroot
          UrlVarArray = Application("FrontPage_UrlVars")
          for i = 0 to UBound(UrlVarArray)
               if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArray(i))
          next
     end if
     Application.Unlock
End Sub
Sub FrontPage_MapUrl(AppVarName)
     ' 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("FrontPage_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("Scripting.Dictionary")
     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),"provider=") < 1 and Len(Application(sName & "_ConnectionTimeout"))>0 then
                    sArr = Split(sConn,";")
                    set oDict = Server.CreateObject("Scripting.Dictionary")
                    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.OLEDB.4.0;Data 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-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:connectionstatus msdt:dt="string">myspace=1</mso:connectionstatus>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
Avatar of rockiroads
rockiroads
Flag of United States of America image

How is your Javascript?

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


Avatar of vallowens
vallowens

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

cool is it anyway u can giv me an example of this? it would be much appreciated
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial