Ok i found this a while back and i am trying to mod it so it works but it keeps not updating the users online and kills my other code?
Well i got it working but it dont update when i login?
It says 14 guest now, and i am logged in so it sould ream me as member.....
And how do i make a cron job, the tutorial says it lowrs site badwith and it runs better updating records?
The first step in creating your "who's online" counter is to setup a table in your database. Here's the table that I used:
Code:[code=mysql]
CREATE TABLE trv_online (
session_id varchar(255) NOT NULL default '',
activity datetime NOT NULL default '0000-00-00 00:00:00',
member enum('y','n') default 'n',
ip_address varchar(255) NOT NULL default '',
refurl varchar(255) NOT NULL default '',
user_agent varchar(255) default NULL,
PRIMARY KEY (session_id),
KEY session_id (session_id)
) TYPE=MyISAM;[/code]
The first script we'll dig into is going to be included as a file at the top of every php script on your website. Hopefully you have a global header file that you can simply do this only one time. Here's the script:
Code:[code=php]
if(!session_is_ registered('onl ine')){
@mysql_query("I NSERT INTO trv_online (session_id, activity, ip_address, refurl, user_agent)
VALUES
('".session_id( )."', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGEN T']}')");
session_registe r('online');
} else {
if(session_is_r egistered('user _id')){
@mysql_query("U PDATE trv_online SET activity=now(), member='y' WHERE session_id='".s ession_id()."'" );
}
}[/code]
Place in body:
Code:[code=php]
<?
// This file is included into your website
// Preferably a MySQL connection has been established already
$limit_time = time() - 300; // 5 Minute time out. 60 * 5 = 300
$sql = mysql_query("SE LECT * FROM trv_online WHERE UNIX_TIMESTAMP( activity) >= $limit_time AND member='n' GROUP BY ip_address") or die (mysql_error()) ;
$sql_member = mysql_query("SE LECT * FROM trv_online WHERE UNIX_TIMESTAMP( activity) >= $limit_time AND member='y' GROUP BY ip_address") or die (mysql_error()) ;
$visits = mysql_num_rows( $sql);
$members = mysql_num_rows( $sql_member);
echo "People Online:<br />";
echo "Guests Online: $visits<br />";
echo "Members Online: $members<br />";
?>[/code]
Code:[code=mysql]
CREATE TABLE trv_online (
session_id varchar(255) NOT NULL default '',
activity datetime NOT NULL default '0000-00-00 00:00:00',
member enum('y','n') default 'n',
ip_address varchar(255) NOT NULL default '',
refurl varchar(255) NOT NULL default '',
user_agent varchar(255) default NULL,
PRIMARY KEY (session_id),
KEY session_id (session_id)
) TYPE=MyISAM;[/code]
The first script we'll dig into is going to be included as a file at the top of every php script on your website. Hopefully you have a global header file that you can simply do this only one time. Here's the script:
Code:[code=php]
if(!session_is_ registered('onl ine')){
@mysql_query("I NSERT INTO trv_online (session_id, activity, ip_address, refurl, user_agent)
VALUES
('".session_id( )."', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGEN T']}')");
session_registe r('online');
} else {
if(session_is_r egistered('user _id')){
@mysql_query("U PDATE trv_online SET activity=now(), member='y' WHERE session_id='".s ession_id()."'" );
}
}[/code]
Place in body:
Code:[code=php]
<?
// This file is included into your website
// Preferably a MySQL connection has been established already
$limit_time = time() - 300; // 5 Minute time out. 60 * 5 = 300
$sql = mysql_query("SE LECT * FROM trv_online WHERE UNIX_TIMESTAMP( activity) >= $limit_time AND member='n' GROUP BY ip_address") or die (mysql_error()) ;
$sql_member = mysql_query("SE LECT * FROM trv_online WHERE UNIX_TIMESTAMP( activity) >= $limit_time AND member='y' GROUP BY ip_address") or die (mysql_error()) ;
$visits = mysql_num_rows( $sql);
$members = mysql_num_rows( $sql_member);
echo "People Online:<br />";
echo "Guests Online: $visits<br />";
echo "Members Online: $members<br />";
?>[/code]
It says 14 guest now, and i am logged in so it sould ream me as member.....
And how do i make a cron job, the tutorial says it lowrs site badwith and it runs better updating records?
[code=php]if(session_is_r egistered('onli ne')){
@mysql_query("U PDATE trv_online SET activity=now() WHERE session_id='".s ession_id()."'" );
}
// Database connection information here
$maxtime = time() -100;
$sql = mysql_query("DE LETE FROM trv_online WHERE UNIX_TIMESTAMP( activity) < '$maxtime'");
$rows = mysql_affected_ rows();[/code]
@mysql_query("U PDATE trv_online SET activity=now() WHERE session_id='".s ession_id()."'" );
}
// Database connection information here
$maxtime = time() -100;
$sql = mysql_query("DE LETE FROM trv_online WHERE UNIX_TIMESTAMP( activity) < '$maxtime'");
$rows = mysql_affected_ rows();[/code]
Comment