Author |
Message |
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Thu Feb 20, 2003 11:34 am (21 years, 2 months ago) |
|
I need a counter that will count, the users viewing my site currently, and the maximum amount of users on my site at one time, any suggestions?
I have PHP and MySQL access.
Thanks |
________________________________ www.celldamage.org |
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Thu Feb 20, 2003 5:48 pm (21 years, 2 months ago) |
|
you could always find the relevant bit of code in a forum and somehow work that into your site...seems like a complicated thing to try to write from scratch |
________________________________ It's turtles all the way down... |
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Fri Feb 21, 2003 10:09 am (21 years, 2 months ago) |
|
i don't have any experience with forums to do that, if anyone could find me such a code it would be very helpful |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Feb 22, 2003 9:17 am (21 years, 2 months ago) |
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Sat Feb 22, 2003 11:10 am (21 years, 2 months ago) |
|
|
|
|
Ben
Senior WebHelper
Joined: 08 Jan 2002
Posts: 431
Location: Liverpool - UK
|
Posted:
Sat Feb 22, 2003 7:46 pm (21 years, 2 months ago) |
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Wed Feb 26, 2003 8:21 pm (21 years, 1 month ago) |
|
has anyone found a way to make a 'most online users' thing yet?
thanks for those guys!! |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Wed Feb 26, 2003 8:30 pm (21 years, 1 month ago) |
|
What is wrong with the links provided above? Do you mean that you require the "most users online" thing as well as "x users online"? |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Wed Feb 26, 2003 8:32 pm (21 years, 1 month ago) |
|
The links above are very helpful and i have used them and found a script i needed
But i could also do with a most online users too, i understand i'm nagging you |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Wed Feb 26, 2003 8:36 pm (21 years, 1 month ago) |
|
Which one did you use? We can't help you unless we know which one you chose |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Sun Mar 02, 2003 5:32 pm (21 years, 1 month ago) |
|
I used this code :
Code: | <?php
$server = "localhost";
$db_user = "...";
$db_pass = "...";
$database = "...";
$db = mysql_connect($server, $db_user,$db_pass);
mysql_select_db($database,$db);
$timeoutseconds = 900; //5 minutes
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
$insert = mysql_query("INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')",$db);
if(!($insert)) {
print "Useronline Insert Failed > ";
}
$delete = mysql_query("DELETE FROM useronline WHERE timestamp<$timeout",$db);
if(!($delete)) {
print "Useronline Delete Failed > ";
}
$result = mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'",$db);
if(!($result)) {
print "Useronline Select Error > ";
}
$user = mysql_num_rows($result);
mysql_close();
if($user == 1) {
print("<font class=userinfotitle>Users online:</font><font class=userinfotext> $user\n</font>");
} else {
print("<font class=userinfotitle>Users online:</font><font class=userinfotext> $user\n</font>");
}
?> |
|
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Mar 02, 2003 5:49 pm (21 years, 1 month ago) |
|
OK, you should now create a table like this:
Code: | CREATE TABLE config (
config_name varchar(255) NOT NULL,
config_value varchar(255) NOT NULL,
PRIMARY KEY (config_name)
); |
Then add some code to this effect:
Code: | $most_online = mysql_query("SELECT config_value FROM config WHERE config_name = 'most_online'",$db);
while ($row = mysql_fetch_array($most_online, MYSQL_ASSOC)) {
$row['config_value']=$most_online2;
}
if ($user>$most_online2) {
$update_online = mysql_query("UPDATE config SET config_value = $user WHERE config_name = 'most_online'",$db);
} |
There's probably something wrong with this code, but the idea's there
You'll have to add a row into the config table with:
config_name='most_online' and config_value=0. |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Sun Mar 02, 2003 8:12 pm (21 years, 1 month ago) |
|
should i put that table in a new database or just add to the one i have? |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 7:07 am (21 years, 1 month ago) |
|
Add it to the one you have. |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Mon Mar 03, 2003 5:39 pm (21 years, 1 month ago) |
|
|
|
|
|