Show the Number of Users Online
(Page 1 of 2 )
Learn how to show the number of users on your site who are online using the power of PHP.
By : Akash Goel
This tutorial has been graciously provided by spoono.com
This script will explain how to display the number of users online using your website. You have to put this on everypage you want it to appear. It can be broken down into 2 sections. The first is creating the table, and the second is the PHP script itself. Beware you should have knowledge of PHP before attempting this. We also reccommend you have PhpMyAdmin :)
Alright log on to PhpMyAdmin and make a new database called "users". We are going to insert 3 fields into a new table called useronline called timestamp, ip, and file. Lets dump the following code into the Users database using the form on the PhpMyAdmin page:
CREATE TABLE useronline ( timestamp int(15) DEFAULT '0' NOT NULL, ip varchar(40) NOT NULL, file varchar(100) NOT NULL, PRIMARY KEY (timestamp), KEY ip (ip), KEY file (file) ); |
Alright Now lets create the PHP script. Its rather large and lets hope you can follow along. Here is what we'll do in English: 1. Give the server info. 2. Get the time. 3. Insert the values of the person thats online into the mySQL, then create the Failed response if it failed. 4. Do the same thing but delete the user from the database when he leaves 5. Grab the results. 6. Output the results.
Next: The Code >>
More Miscellaneous Articles
More By Codewalkers