A Better Who's Online Script (A.B.W.O.S.) By Mike L. (ontarioabandonedplaces.com) Based on an original script by Alex Robson Introduction ============ As many programmers know, the GLOBAL.ASA file can be used to track the number of online users to your website. This method uses Session_OnStart to increment a counter whenever you receive a new visitor. The result might appear something like this: "11 Users Online" Pretty boring huh? After searching the internet, I found many scripts that worked on the GLOBAL.ASA principle and that only COUNTED active users. What I was looking for though, was a script that would show me the NAMES of members online instead of simply telling me how many members were online. While searching for a script to do just this, I found that other programmers were also looking for a similar script. Finally I came across a script written by Alex which did exactly what I was looking for. I improved the script and added some new features. Here is what A.B.W.O.S. will do for you: - If a member is not in the database, it adds them (making them ACTIVE). - If a member is already in the database, it updates their stats (keeping them ACTIVE). - If a member is inactive for a set period of time, it purges them from the database (INACTIVE). - The script will display what page the user is currently viewing (eg. index.asp, whosonline.asp) - The script will show you how long the user has been idle (since last page request) - An improved WHOSONLINE display - The script will display GUESTS to the website (unregistered users, bots, etc.) if they don't have a username. INSTALLATION ============ FILES ONLINEDB.MDB This is the Access database. Place it into a folder with write/modify permissions. WHOSONLINE.ASP This file will display a listing of what users are currently online. For privacy reasons you may want to make this an administrator feature only or remove the feature that displays what pages members are currently viewing. Edit this file so that "Strconn" contains the proper path to the ONLINEDB.MDB database. The default directory is \DBASE\ONLINE.MDB Edit the "tmout" variable to set how many minutes before removing idle users. UPDATER.ASP This file is the script which actually updates the database. It should be added to your website to all areas where tracking is necessary. For example you would want to add it to your forum, change password page, stats, chat, news, etc. pages. This may require you to modify many files on your existing webpage or, if you're like me, have a header file which is displayed on all of your pages so you need only edit that one header file. Use this line of code for all pages you want tracked: You may need to alter the path (eg. "../UPDATER.ASP" if calling the script from other than root directory) =============================================== * * * FOOLPROOF INSTALLATION INSTRUCTIONS * * * =============================================== 1) Extract the ONLINEDB.MDB database and put it into a folder with write permissions. 2) Modify the WHOSONLINE.ASP file to reflect the path to the database and to edit the "tmout" variable (in minutes) to choose when to purge inactive members. Example: "tmout = 12" will purge anyone idle for 12 minutes 3) READ CAREFULLY! Obviously the UPDATER.ASP file needs to know what user is logged into your site before it updates the database. This can be accomplished a few ways. You can set a session variable from your login page or set a cookie. I am assuming that if you are already running a member-based website, that you have some form of determining who is logged on. You must pass the username into the variable called "strCookieName". You may also set the strCookieName to null if you want to use SessionID instead (eg. non-member websites). Read the UPDATER.ASP file for my comments on ways to do this. 4) Modify the UPDATER.ASP file to reflect the path to the database. Questions ========= - How do I add a member to the active list once they have logged in successfully? There is no need to do this as they will be added to the WHOS ONLINE list the moment they request a webpage containing the updater.asp code - How do I remove a member when they close the browser instead of logging out? When the user's session times out, they will be purged from the WHOS ONLINE list. - How do I remove a member when they logout? This is easily done but my brain hurts so you'll have to wait for a newer version. - Do I need to include the updater.asp file in all of my webpages? You need to include it wherever you want an action to occur. The action being, their idle status will be set to zero, they will be added to WHOS ONLINE list if not already on it, and the page they are viewing will be displayed in the WHOS ONLINE list. Unless you insert the INCLUDE line of code, nothing will happen. - What is the include line of code? Place it inside your asp files (index.asp, default.asp, etc etc etc). Where in your code you decide to place it is not really crucial. - Can I use this script even if I don't have membership on my site? Yes! You will have to edit the UPDATER.ASP file so that strcookiename is null (strCookieName = "" will do just fine and my code will generate them a GUEST ID) - I'm seeing numerous GUESTS when I open a new browser window. A new Session ID is generated by ASP whenever a new webpage is requested from the server. They will be purged naturally in due time. In the enclosed file "screenshot.jpg" you can see a working example of the script on my website. An actual user named "tester" was browsing a location titled Depot Harbour, I was logged in as Administrator and viewing a location titled Skead, and three guests were logged in (myself in new browser windows). Enjoy! Questions? contact(at)ontarioabandonedplaces.com