hi
i'm still in the beguining of php and copy/paste this script, which shows the number of users online. I presume i gave 10 minutes to active user being in the site, and after it it was suposed the script deleted it from database.
But that isnt happening, and why i dont know.
i've a table:
CREATE TABLE users_online (
horas int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
ficheiro varchar(100) NOT NULL,
PRIMARY KEY (horas),
KEY ip (ip),
KEY ficheiro (ficheiro)
);
here's the code:
<?php
$server = "***";
$db_user = "***";
$db_pass = "***";
$database = "***";
$tempofora = 600;
$PHP_SELF = $_SERVER['PHP_SELF'];
$horas = time();
$timeout = $horas-$tempofora;
$REMOTE_ADDR=getenv("REMOTE_ADDR"
;
mysql_connect($server, $db_user, $db_pass);
$adiciona = mysql_db_query($database, "INSERT INTO users_online VALUES
('$horas','$REMOTE_ADDR','$PHP_SELF')"
;
if(!($adiciona)) {
print "Ocorreu um erro!";
}
$apaga = mysql_db_query($database, "DELETE FROM users_online WHERE $horas < $timeout"
;
if(!($apaga)) {
print "Ocorreu um erro!";
}
$resultado = mysql_db_query($database, "SELECT DISTINCT ip FROM
users_online WHERE ficheiro='$PHP_SELF'"
;
if(!($resultado)) {
print "Ocorreu um erro!";
}
$user = mysql_num_rows($resultado);
mysql_close();
if($user == 1) {
print("$user utilizador online\n"
;
} else {
print("$user utilizadores online\n"
;
}
?>
The line of code i dont understand how it works is this one:
$apaga = mysql_db_query($database, "DELETE FROM users_online WHERE $horas < $timeout"
;
doesnt the script should delete olders entries?
Can someone help me please, since i can see from database that the script doesnt clear old entries...
i'm still in the beguining of php and copy/paste this script, which shows the number of users online. I presume i gave 10 minutes to active user being in the site, and after it it was suposed the script deleted it from database.
But that isnt happening, and why i dont know.
i've a table:
CREATE TABLE users_online (
horas int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
ficheiro varchar(100) NOT NULL,
PRIMARY KEY (horas),
KEY ip (ip),
KEY ficheiro (ficheiro)
);
here's the code:
<?php
$server = "***";
$db_user = "***";
$db_pass = "***";
$database = "***";
$tempofora = 600;
$PHP_SELF = $_SERVER['PHP_SELF'];
$horas = time();
$timeout = $horas-$tempofora;
$REMOTE_ADDR=getenv("REMOTE_ADDR"
mysql_connect($server, $db_user, $db_pass);
$adiciona = mysql_db_query($database, "INSERT INTO users_online VALUES
('$horas','$REMOTE_ADDR','$PHP_SELF')"
if(!($adiciona)) {
print "Ocorreu um erro!";
}
$apaga = mysql_db_query($database, "DELETE FROM users_online WHERE $horas < $timeout"
if(!($apaga)) {
print "Ocorreu um erro!";
}
$resultado = mysql_db_query($database, "SELECT DISTINCT ip FROM
users_online WHERE ficheiro='$PHP_SELF'"
if(!($resultado)) {
print "Ocorreu um erro!";
}
$user = mysql_num_rows($resultado);
mysql_close();
if($user == 1) {
print("$user utilizador online\n"
} else {
print("$user utilizadores online\n"
}
?>
The line of code i dont understand how it works is this one:
$apaga = mysql_db_query($database, "DELETE FROM users_online WHERE $horas < $timeout"
doesnt the script should delete olders entries?
Can someone help me please, since i can see from database that the script doesnt clear old entries...