Web Analytics Made Easy -
StatCounter Global.asa / Session_OnEnd - CodingForum

Announcement

Collapse
No announcement yet.

Global.asa / Session_OnEnd

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Global.asa / Session_OnEnd

    I am tracking all activity on one of my sites, but if the user does not hit the LOGOUT button, I don't get a Logged out entry. I would like to stick it into the global.asa file so that it will do it when their session ends no matter how they exit.

    This code below is what I have in my asa file now, but does not seem to be working.
    Code:
    Sub Session_OnEnd
      IF Session("USER_ID") <> 0 THEN
      	oDb = Server.CreateObject("adodb.connection")
        ConnStr = "[COLOR=orangered]SQL CONNECTION STRING[/COLOR]"
        oDb.Open(ConnStr)
        oDb.Execute("INSERT INTO Log (mLogin, IP, EventTime, EventDescr)  VALUES("+Session("USER_ID")+", '"+Session("USER_IP")+"', GetDate(),'Log Out')")
      END IF
    
    End Sub
    Any ideas?
    "Never offend people with style when you can offend them with substance."
    --Sam Brown

  • #2
    That is a good question, but I don't know if there's an easy (or possible) way to track this, since someone can simply close their browser window...

    I'll need to think about that one for awhile. Anyone else have an idea?

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

    Comment


    • #3
      Re: Global.asa / Session_OnEnd

      Originally posted by Eskimo
      I am tracking all activity on one of my sites, but if the user does not hit the LOGOUT button, I don't get a Logged out entry. I would like to stick it into the global.asa file so that it will do it when their session ends no matter how they exit.

      This code below is what I have in my asa file now, but does not seem to be working.
      Code:
      Sub Session_OnEnd
        IF Session("USER_ID") <> 0 THEN
        	oDb = Server.CreateObject("adodb.connection")
          ConnStr = "[COLOR=orangered]SQL CONNECTION STRING[/COLOR]"
          oDb.Open(ConnStr)
          oDb.Execute("INSERT INTO Log VALUES("+Session("USER_ID")+", '"+Session("USER_IP")+"', GetDate(),'Log Out')")
        END IF
      
      End Sub
      Any ideas?
      Try that.
      OracleGuy

      Comment


      • #4
        D'oh - a great solution. Why didn't I think of using a Session Variable?
        Former ASP Forum Moderator - I'm back!

        If you can teach yourself how to learn, you can learn anything. ;)

        Comment


        • #5
          Originally posted by whammy
          D'oh - a great solution. Why didn't I think of using a Session Variable?
          Yeah... I share your confusion Dave. Did George know what he was doing when he gave whammy a mod gun?
          OracleGuy

          Comment


          • #6
            I'm the confused one. I gotta pay more attention. *sigh* :-/
            Former ASP Forum Moderator - I'm back!

            If you can teach yourself how to learn, you can learn anything. ;)

            Comment


            • #7
              Originally posted by whammy
              D'oh - a great solution. Why didn't I think of using a Session Variable?
              Do you mean you didn't think of just putting the code in the session_OnEnd in the global.asa(x)?
              OracleGuy

              Comment


              • #8
                Re: Re: Global.asa / Session_OnEnd

                If the user clicks the X button of the browser or hits Alt+F4, Session_OnEnd is not executed. I also experienced that before. One alternative is this: (unfortunately, for IE only)

                Call this on window onunload event on every page:

                function onUnloadPage()
                {
                if (document.all){
                if ((window.event.clientX < 0) && (window.event.clientY < 0)) //X button is clicked
                {
                //call your logout page
                window.open('logout.asp', '', "features");

                //or silent logout
                //logout = new Image();
                //logout.src="logout.asp";
                }
                }
                }


                Originally posted by Dave Clark


                My question is... Have you established a default timeout value for the Session? If you have, then it shouldn't matter whether the visitor logs out or merely closes their browser without logging out. The Session timeout should still cause the Session End event to fire.
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  Sorry guys, I have been out of town for the last few days.

                  Even if somone is to close a browser, their Session still times out (default=20min), and should run the Session_OnEnd script. I have this (IF Session("USER_ID") <> 0 THEN) to gard aginst it running if they actually press the LOGOUT button, which few ever really do anyway.

                  I may have to go with the onUnLoad event for IE. This is used on an Intranet where IE6+ is required.

                  However, that won't allow me to find an answer to my question, only duct tape for this problem. I really would like to find a way to accomplish this, if I find out what it is, I will post it back here.
                  "Never offend people with style when you can offend them with substance."
                  --Sam Brown

                  Comment


                  • #10
                    I've had a problem doing the exact same thing as you're trying to accomplish.

                    I haven't completely found a way around this yet, but I was thinking of using Application variables instead of session variables.

                    You need to make sure that your directory is set up as an application in IIS

                    I haven't really tried this yet to see if it'll work.. but the application varible syntax is the same as session..

                    so in global.asa
                    --------------------------
                    Sub Application_OnEnd
                    your code here
                    End Sub
                    --------------------------

                    I'll let you know if I get anywhere

                    ~Quack

                    Comment


                    • #11
                      Application variables don't run when a user closes his browser. They run only when you Restart IIS, or when you edit the Global.asa file.

                      I don't think that will enable me to do what I need. But you have given me an idea.

                      The Sesson_OnStart scripts are working, but the Session_onEnd scripts are not.

                      Do I need to have : Application_onStart and Application_onEnd listed even though I'm not using them?
                      "Never offend people with style when you can offend them with substance."
                      --Sam Brown

                      Comment


                      • #12
                        I guess it wouldn't hurt to have those in there - but I really don't think that's gunna change the problem.

                        To use something like an onUnload function would be really tricky - but could work - you could put it in an invisible frame that would fire the 'logout' page when the user exits the browser.

                        Also, when the user clicks the logout button, you could redirect the invisible frame to another page location (which would fire the onUnload function of the top frame, sending it to the logout page.)

                        I would say to have the unload function fire the page that calls the Session.Abandon function (which would then cause Session_OnEnd to execute) into a new window (set the width and height to 0 and have it close the window when it's finished)

                        Let me know if this helps

                        ~Quack

                        Comment


                        • #13
                          I have chosen not to use the unLoad event.

                          Only for the reason of knowledge. I can't stand the fact that I don't know whats wrong with this. But I will find out, and this will work like its supposed to.

                          I agee with you, I don't think putting the appOnEnd or appOnStart will help anthing, must have been to early in them morning for my mind to function correctly. (Need more coffee...uhh).

                          I know it has to be some little detail that I have overlooked. This is my goal today, to fix this..
                          "Never offend people with style when you can offend them with substance."
                          --Sam Brown

                          Comment


                          • #14
                            Let me know what you come accross, I've been trying to do a similar thing...

                            I have a site with many users - want to try and see if I can get a list of people who are logged in - but sometimes Session_OnEnd does not fire... so it still says the users is logged in (even after Sesison time out)

                            Is this kinda like what you're trying?

                            As far as my thing with the Application stuff - I was thinking of using a combination of application variables and session variables.

                            ~Quack

                            Comment


                            • #15
                              You may be right, it may have to be a combination of the two..mmmm.

                              I bet your right, in order to have the Session_OnEnd to even be detected, you may need to have an Application_ running. I'll try that right now and see what I can get working.

                              I'm not trying to get a list of USERS ONLINE, I'm trying to track activity on a site that I designed. Any inserts/updates/deletes to the Database, what Table and Row was effected, who did it, when they did it, IP....blah blah blah. But with what I have right now, I can't tell when they logged off, unless they actuall press the LOGOUT button. Which few do.
                              "Never offend people with style when you can offend them with substance."
                              --Sam Brown

                              Comment

                              Working...
                              X