View Full Version : Displaying number of visitors.
ionsurge
11-29-2002, 05:54 PM
Hello all.
Can anyone tell me how I should go about displaying the number of visitors that are on my site when someone goes there? I would appreciate code, but I do not mind urls.
It is like what you have here, where it says that there are currently x number of members and x number of guests.
Thank you.
Ionsurge.
I'm sure you can find scripts that do this on Hotscripts.com or php.resourceindex.com. If you want to code your own, please post what you have so far.
Thanks,
ionsurge
11-30-2002, 12:16 PM
Will do WA... I think I have got the hang of it... (I am trying to write it)
Will get back to you in a mo.
Ionsurge.
piniyini
12-01-2002, 01:08 PM
This may help ...
http://codewalkers.com/seecode/75.html
Laterz ...
Ankun
12-02-2002, 05:59 AM
not that I absolutely need this..but how about one that doesnt use mysql? (I might feel like using it later possibly..) and btw dude there are TONS of scripts out that do that for you anyway, unless you really want to write you own.
ionsurge
12-02-2002, 11:27 AM
Thankx toseef, that is a nice slice of script... I may give it a whirl.
The reason for me wanting to write my own stuff is due to all the hassle with copyright infringement, permissions, praises and all that. Also, the additional factor that others who write the code that want a link to their site, which is a form of advertising, which I am not alto fond of, as you may have noticed from my posts and my website too. Getting someone elses work is just way too much.
Everything on my site is so far done solely by me, and no one else. So, now I don't need to worry about copyright infringement etc.
I have almost got my head around it. When it is done, I will post it here.
And no, all those who want to use this code that I am writing at the mo will be able to use it freely, without needing to link to my site.
Ionsurge.
Originally posted by Ankun
not that I absolutely need this..but how about one that doesnt use mysql? (I might feel like using it later possibly..) and btw dude there are TONS of scripts out that do that for you anyway, unless you really want to write you own.
Well, a "who's online" script requires constant deletion and insertion of data. Depending on how popular your site is, using a flat file to record all this information is probably not the best idea. mySQL makes the process a lot more efficient.
By deletion and insertion, I mean keeping track of all incoming IP addresses, and deleting those that expire (ie: past 15 minutes in the event of vBulletin's whos online style).
ionsurge
01-01-2003, 04:13 PM
I forgot about this thread, but anyhow I did find this, which was useful, (from www.yaxay.com)
Learn how to show the number of users on your site who are online using the power of
PHP. 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:
code:
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:
Give the server info.
Get the time.
Insert the values of the person thats online into the mySQL, then create the Failed
response if it failed.
Do the same thing but delete the user from the database when he leaves
Grab the results.
Output the results.
Finally, here is the PHP Code:
PHP:
<?php_
//fill in some basic info
$server_=_"localhost";_
$db_user_=_"username";_
$db_pass_=_"password";_
$database_=_"users";_
$timeoutseconds_=_300;_
//get the time
$timestamp_=_time();_
$timeout_=_$timestamp-$timeoutseconds;_
//connect to database
mysql_connect($server,_$db_user,_$db_pass);_
//insert the values
$insert_=_mysql_db_query($database,_"INSERT_INTO_useronline_VALUES
('$timestamp','$REMOTE_ADDR','$PHP_SELF')");_
if(!($insert))_{_
print_"Useronline Insert Failed > ";_
}_
//delete values when they leave
$delete_=_mysql_db_query($database,_"DELETE_FROM_useronline_WHERE_timestamp<$t
imeout");_
if(!($delete))_{_
print_"Useronline Delete Failed > ";_
}_
//grab the results
$result_=_mysql_db_query($database,_"SELECT_DISTINCT_ip_FROM_useronline_WHERE_fil
e='$PHP_SELF'");_
if(!($result))_{_
print_"Useronline Select Error > ";_
}_
//number of rows = the number of people online
$user_=_mysql_num_rows($result);_
//spit out the results
mysql_close();_
if($user_==_1)_{_
print("$user_user_online\n");_
}_else_{_
print("$user_users_online\n");_
}_
?>_
No author notices needed, as far as I can see.
Ionsurge
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.