Visitors Online

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Visitors Online

Post by m3mn0n »

does anyone know the neat trick that enables a veiwing of the current visitors online on the page? thx!
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

I have seen one solution that stores a username and a timestamp in a table when the user accesses to site. The timestamp gets updated everytime the user loads a new page. Then there are a cron job running every now and then wich removes users no longer at the site (read with an old timestamp).

Then it's just to count how many rows there are in the table and there you have how many users currently online. This way you can list which users you have online as well.

If you don't use usernames you can use the clients ip- or hostname.
:idea:
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

haagen described the most common way to do it. however, instead of a cron job, you can have the cleanup process be handled in the page load (this is especially effective if you don't have access to cron).

it doesn't matter if entries stay in the table for extended periods of time because as soon as someone visites the site (the only time the table's contents really matter) then the table will be cleaned up.

just make sure you do the cleanup before building a list of current users.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

you will log the time stamp, and IP

when some access it, it will check that they aren't logged, and if they aren't it will add them.

also, upon every run of the script, it will delete old ones judging on the timestamp.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

is there no simpler way to do this? newbie friendly maybe? ;)
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

The only way to get good at programming, IMHO, is to forget what is 'newbie friendly', pick a poject (this seems like a pretty good one), and get obsessed with it. Do it yourself, ask questions if you really get stuck, but roll up your sleeves and spend a few nights coding for real.

In my experience, just when you're ready to tear your hair out, you'll have a flash and it'll all come to you. That high is why I'm addicted to programming, and maybe you'll catch it too :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

yea i relized that exactally too! :)

but what i find the most "hard to stomach" is the fact that no site i've seen so far has any step by step learning of the basics, even the book i have doesn't give me enough detail to what i want to learn.

I know there is a place somewhere, where people learn how to do all these crazy things i've been seeing on some of your sites, i just want to know where it is so i can get a cut in on the action, if ya know what i mean ;)
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Oromian,
It is helpful to understand the basic concepts of programming. Not knowing you age/employment makes it hard to give good advice but if you can, take some intro programming courses at the local University. A few short courses in C++ will give you the basic tools you need. After that, necessity drives invention.

Direwolf
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

University course eh?

It seems a bit much but I will look into that as an option. :)
Post Reply