I know I asked this a while in the past but I figure I'd give it another go.
This users online script shows the current users online. It does NOT accurately report back the number of users that were seen in the last 24 hours. This number just grows infinitely each day.
Does anyone know how to fix this part of the database so it keeps accurate records?
setup script
Perl script
This users online script shows the current users online. It does NOT accurately report back the number of users that were seen in the last 24 hours. This number just grows infinitely each day.
Does anyone know how to fix this part of the database so it keeps accurate records?
setup script
Code:
my $sth = $dbh->prepare(
"CREATE TABLE IF NOT EXISTS day_time
(
id int auto_increment NOT NULL,
ip VARCHAR(16) NOT NULL,
time INTEGER NOT NULL,
location VARCHAR(50) NOT NULL,
primary key (id)
)");
$sth->execute();
if ($sth->errstr) { print $sth->errstr; }
else { print "day_time table created.<br>"; }
Perl script
Code:
.
. sample of adding the day_time data
.
my $data = qq(INSERT INTO day_time (ip, time, location) VALUES(?,?,?));
my $sth = $dbh->prepare($data);
$sth->execute("$userip", time(), "$ENV{'HTTP_REFERER'}") or die $dbh->errstr;
################################
# Remove expired users from now_time and day_time tables
################################
my $timenow = time();
$minutes = $minutes * 60;
my $timemin = $timenow - $minutes;
my $data = qq(DELETE FROM now_time WHERE time < "$timemin");
my $sth = $dbh->prepare($data);
$sth->execute() or die $dbh->errstr;
my $day = 60 * 60 * 24;
my $timeday = $timenow - $day;
my $data = qq(DELETE FROM day_time WHERE time < $timeday, Interval 24 Hour));
my $sth = $dbh->prepare($data);
$sth->execute() or die $dbh->errstr;