Recreating or Emulating Session_OnEnd() without GL

Results 1 to 2 of 2

Thread: Recreating or Emulating Session_OnEnd() without GL

  1. #1
    Join Date
    Dec 1969

    Default Recreating or Emulating Session_OnEnd() without GL

    I need to know how to emulate Session_OnEnd() without using a global.asa file since I do not have access to this with my hosting service. Here are my circumstances:<BR><BR>1. A user logs into website using a login form, username is extracted from database, stored in a Session variable, and added to the end of an Application variable that shows the usernames of people currently using the website. I already have this part down.<BR><BR>2. The user decides to leave the website, so the Session variable storing his username soon expires, but his username is not removed from the list of current users in the Application variable because I cannot remove this using Session_OnEnd() because I do not control global.asa.<BR><BR>So what I need to have is an alternate way (besides global.asa) to see if the user is still on the website or not so it will remove him from the list.<BR><BR>I have already tried the script that stores the SessionID and the time of the last request of the server in a log file and the name is removed when the user does not respond after a specified amount of time, but this solution will not work for me either since I do not have write access. So please no scripts that require databases or FileSystemObjects.<BR><BR>Thank you,<BR>David Bindel<BR>

  2. #2
    Join Date
    Dec 1969

    Default What about App variables?

    First question, what hosting service is this. We need to warn *all* ASP developers to STAY AWAY from it!<BR><BR>But anyway...<BR><BR>Why not use the log file scheme but, instead of using a file, just use an array that you store in an Application variable? It would be tons faster than a file would be, anyway!<BR><BR>So you have an array of arrays (or a 2D array, but the array of arrays will be more efficient).<BR><BR>Something like this could be put at the head of every page (e.g., via an include file):<BR><BR>&#060;%<BR>Dim users, usercount<BR>Application.Lock<BR>&nbsp; &nbsp; If Application("userCount") = "" Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; this is first user since server startup!<BR>&nbsp; &nbsp; &nbsp; &nbsp; ReDim users(100) &#039; arbitrary size<BR>&nbsp; &nbsp; &nbsp; &nbsp; usercount = -1 &#039; actually, max slot number used<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; usercount = Application("userCount")<BR>&nbsp; &nbsp; &nbsp; &nbsp; users = Application("users")<BR>&nbsp; &nbsp; End If<BR><BR>&nbsp; &nbsp; If Session("UserSlot") = "" Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; new user!<BR>&nbsp; &nbsp; &nbsp; &nbsp; usercount = usercount + 1<BR>&nbsp; &nbsp; &nbsp; &nbsp; If usercount &#062; UBound(users) Then ReDim Preserve users(usercount+20)<BR>&nbsp; &nbsp; &nbsp; &nbsp; newuser = Array( userid, Now() )<BR>&nbsp; &nbsp; &nbsp; &nbsp; users( usercount ) = newuser<BR>&nbsp; &nbsp; &nbsp; &nbsp; Session("UserSlot") = usercount<BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; Else <BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; existing user<BR>&nbsp; &nbsp; &nbsp; &nbsp; slotNum = Session("UserSlot")<BR>&nbsp; &nbsp; &nbsp; &nbsp; temp = users( slotNum )<BR>&nbsp; &nbsp; &nbsp; &nbsp; temp( 1 ) = Now() &#039; update the time<BR>&nbsp; &nbsp; &nbsp; &nbsp; users( slotNum ) = temp<BR>&nbsp; &nbsp; End If<BR><BR>&nbsp; &nbsp; &#039; here is where you put logic to remove a user from the users array!<BR>&nbsp; &nbsp; &#039; ... I&#039;ll let you work on that!<BR><BR>&nbsp; &nbsp; Application("users") = users<BR>&nbsp; &nbsp; Application("userCount") = usercount<BR><BR>Application.Unlock<BR>%&#062;<BR> <BR>UNTESTED! Off the top of my head!<BR><BR>What is wrong with it: Instead of just sticking a new user onto the end of the users array, you should check to see if there are any empty slots in the array. Otherwise, it will just grow without limit.<BR><BR>The best way to do that is probably to have a "free list" and a "first free" slot number. I&#039;ll let you work on that one on your own.<BR><BR>Whaddya think?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts