
11/11/2009, 06:32
|
| | Fecha de Ingreso: febrero-2002
Mensajes: 37
Antigüedad: 23 años Puntos: 0 | |
Respuesta: Cambio de servidor y script no funciona Os pego tambien el php por si alguien le puede echar un vistazo, a mi hasta ahora me ha funcionado genial.
Muchas gracias
<?php
global $REMOTE_ADDR, $display;
###############
## VARIABLES ##
###############
// CONFIGURABLE
$data_refresh = 180; // how long before an entry will be deleted in seconds
// DATABASE CONFIGURATION
$db_host = "localhost";
$db_user = "xxxx";
$db_pass = "xxxxx";
$db_name = "xxxxx";
$db_table = "xxxxxx";
// DO NOT EDIT UNLESS YOU KNOW WHAT YOUR DOING
$timestamp = time(); // timestamp variable
$user_ip = $REMOTE_ADDR; // IP address variable
// QUERIES
$online_query = "SELECT * FROM {$db_table}";
$exists_query = "SELECT ip FROM {$db_table} WHERE ip='{$user_ip}'";
$update_query = "UPDATE {$db_table} SET timestamp='{$timestamp}' WHERE ip='{$user_ip}'";
$insert_query = "INSERT INTO {$db_table} (ip, timestamp) VALUES ('{$user_ip}', '{$timestamp}')";
// the delete query is not in this list because it requires the $data array in the delete case
##################
## BEGIN SCRIPT ##
##################
// CONNECT TO DATABASE
$mysql_link = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
// ADD/EDIT ENTRY
if (mysql_num_rows(mysql_query($exists_query)) == 0) {
mysql_query($insert_query);
} else {
mysql_query($update_query);
}
// DELETE OLD ENTRIES
$online = mysql_query($online_query);
while($data=mysql_fetch_assoc($online)) {
$difference = $timestamp - $data[timestamp];
if ($difference > $data_refresh) {
// DELETE QUERY
$delete_query = "DELETE FROM {$db_table} WHERE timestamp='$data[timestamp]'";
mysql_query($delete_query);
$users_online = $users_online - 1;
}
}
$users_online = mysql_num_rows(mysql_query($online_query));
################
## END SCRIPT ##
################
################
## PRINT DATA ##
################
if ($display == "javascript") {
print "document.write('";
}
if ($users_online > 1) {
print "$users_online ";
} elseif ($users_online == "1") {
print "$users_online ";
} elseif ($users_online == "0") {
print "There are no users online.";
}
if ($display == "javascript") {
print "');";
}
?> |