Posted about 1 year ago, by Specific

In this tutorial I intend on teaching the reader how to create their own PHP script to display how many users are online for any given page of their website.

First we must create the table to store our data we collect form each visitor.  The table will hold: A unique ID, Timestamp of when the page was last loaded, IP of the visitor, and file that is viewed.

Below is the SQL to create the usersonline table:

The great thing about creating your own website is that you can customize everything!  For example, on ZoneHacks we added extra information to the table allowing us to determain how many users are logged in as compared to guests.

I assume that the reader has knowledge of how to create the MySQL table above, so I will continue with the logic of how to use this table with PHP and make the users online script.

Like always, when developing I always ask myself a question.
What do I want to do?
 1. Connect to my MySQL database
 2. Get the current time
 3. Insert data collected from the person online into the table created
 4. Delete old records that have expired
 5. Get results and output

Lets get to work:

That is it!  If you have any questions or comments, let me know =)

Author Info Comment