Making an aplication Object

They have: 133 posts

Joined: Sep 2000

Hi there

I was looking for a way to see who was online at my website. Right now I am using a session to store the membernames in, but have been told that I, in order to see who is online, should use an aplication oblect or somethíng like that.
I have never heard the word before, and therefore I don't know how to use it.

Can someone please give me some infromation regarding this? I hope that you can help me.

Thanks in advance

~Casper Bang

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Casper,

The application object is exactly like the session object except that it is global (values are shared), whereas session values are for a specific session, application values are shared between sessions.

To store member names in the application object you would have to setup some way to store them. If you have a list then you could enter that list into the application object onstart in the global.asa:

Sub Application_OnStart
Application("John_Smith")
Application("Dave_Smith")
End Sub

Then when you start a session/member login you access the application value for the member, so if John Smith logged in you would:

Application("John_Smith") = 1

1 could mean logged in. Then when that session expires/member logout you would:

Application("John_Smith") = ""

So to see which members are currently online you would just setup a loop to scan through all application member listing with values of 1.

There are many alternate ways to doing this such as using a database, dictionary object, etc.

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

well... The server that I am at, doesn't support global.asa Sad How can I else do it? I have the membername in a variable, and it is allso stored in a session, so getting that probably wont have to be written in a lot of places - does it?

New members are signing up all the time, so it should be able to be done automaticly; right now there is more than 300 members, but it is increasing soon...

I hope that you can help me do this in another way!

~Casper

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Casper,

It's not going to be reliable without the global.asa. Inside the global.asa there is a Session_OnEnd section that is used to clean up variables when a user's session ends.

The only way around this would be to force the user to hit some kind of "logout" button before they leave, then you could clean up the variables that way.

As for tracking who's online you could use the following:

Application object:
Even though you don't have access to the global.asa file you can should still be able to use the application object. When a member logs in you set their name as "active" in the application variable, and "inactive" when they leave.

Database:
Have a tracking table that stores who's online. When a member logs in you add their ID to the table, when they leave you delete it.

File Object:
Have a text file that you write and delete from. When a user log's in you write a line with their name. When they leave you delete that line.

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Can I set a database to like delete itselves every say 15 minnutes or so? Maybe just once a day (used for another purpose as well), If it cana be auto deleted, I can just make the users check if thehy are there every once in a while...

Can you do that?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

You can use a database to do that, but like I said before, since you don't know when they have left it's not going to be very accurate. Having the table refreshed every 15 minutes isn't really the answer, since that would wipe out members that may still be online. It's possible, but a lot of work and not very efficient.

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

I know that it might not be the best solution, but it might be nessesary...
I can just set it to check if the player is in the DB every time he is at one of the main pages... That wont be a major problem... I just put it in a n include file, that I allready have on all pages!

I allso have to make a database delete itselves every 24 hours... How can I do that? The server is at brinkster.com so I don't know how much they support...

Can you help me here?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

What database platform? If you're using Microsoft SQL Server you can setup a stored procedure that deletes all the records from the table, and then use that stored procedure in a scheduled job to run every 24 hours. You can probably setup something similar on other platforms. If you can't do that, some hosting companies let you schedule ASP files to run.

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

I am using SQL... I m not sure what version though...

Acn you give me an example on how to do it please?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

I made a little mistake, if you're going to schedule a job you don't need to use a stored procedure. Simply add a new job to the SQL Server Agent under Management and select cmdtext as type. Then paste in your sql code into the command window. Then just select the schedule it will run under. If you're on a shared SQL server I doubt you have access to the Management folder since giving everyone access to SQL Server Agent could be disasterous.

PJ | Are we there yet?
pjboettcher.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.