Home | Projects | Downloads | Contact Me | SQL Injection Attacks

WhosOn version 3 coming soon

WhosOn user tracker is just a simple little utility I wrote way back in the day to track users on my corporate intranet.  One of my biggest gripes with it was it was a pain to make changes to it.  If you changed the information you wanted to track about each user there were quite a few other functions you had to change so your changes would be reflected in the output.  Another gripe is the fact the whole thing is more complicated than it needs to be.  I originally wrote the code years ago and I have not really made any attempts to update it.  Version 3 addresses both of these problems.

Originally I stored everything in a two-dimensional array which made things a pain to work with.  Now I create all the basic information I want to track on a user in a structure and just append our structure into the activeuser array.  If we are updating a users information we find their location in the activeusers array and update the structure members.

The other problem was making modifications to the function that actually creates the query object from the activeusers array.  Before, every change required modifying the WhosOnline() function to reflect those changes.  Version 3 will take a look at the elements in your user structure and dynamically create the fields for the query object.

Comments
John Farrar's Gravatar I like basically where you are going with this but I would like to see what the data structure is for this concept.

1. Why is the storage structure of choice a query? Is that just an output from structure or what?

2. Are you actually storing the user as an object?

Not sure what your approach is here.
# Posted By John Farrar | 11/6/07 5:33 PM
Shane Zehnder's Gravatar The users are actually stored as an array of structures in an application-scoped variable. It is possible to access the array directly to get the information, I just chose to write a function to dump it out as a query because queries are easy to work with.

Here is an excerpt out of the new code showing how user information is added:

            userData=structNew();
            
            // This defines the information tracked on your user
            
            userData.UserID=WhosOn.thisUser;
            userData.ClientID=WhosOn.thisClient;
            userData.Created=Now();
            userData.LastUpdated=Now();
            userData.IP=CGI.REMOTE_ADDR;
            userData.CurrentPage=urlPrefix & CGI.SCRIPT_NAME;
            if(len(CGI.QUERY_STRING)) userData.CurrentPage=userData.CurrentPage & "?#CGI.QUERY_STRING#";
            
            arrayAppend(application.activeusers,userData);
            userCount=arrayLen(application.activeusers);

This creates the user in the array. After the user has been created I just pretty much update whichever members need to be updated, namely the LastUpdated member and the CurrentPage member.

I streamlined the WhosOnline() function so that it matches the activeuser structure. Before it required some modification if you added anything into WhosOnPageTracker(). Now it is handled on the fly:

   <cfloop from="1" to="#arrayLen(application.activeusers)#" index="n">
      <cfset ptrData=application.activeusers[n]>
      <cfset QueryAddRow(myQuery)>
      <cfloop item="c" collection="#ptrData#">
         <cfset querySetCell(myQuery,c,ptrData[c])>
      </cfloop>
   </cfloop>

All the revisions before were pretty much crafted for my sites. This version is just going to be a bare-bones release that you can modify to fit your needs. Hopefully it will be easier for people to incorporate into their sites.

The next version is probably going to move to a component. This is a handy little system, but I am quickly outgrowing it.

I hope this addressed your questions.
# Posted By Shane Zehnder | 11/7/07 9:55 AM
Layout: Shane Zehnder ::: BlogCFC was created by Raymond Camden. ::: This blog is running version 5.9.