Code: Select all
<?php
/*
#################################################################################################
#
# File name : useronline.php
# Version : 1.0
# Created By : TeeJay
# Created on : 07 Jan 2003
# e-mail : teejay@webdesigning.demon.co.uk
# Copyright : 2003 by Webdesigning Templates & Scripts
# Website : http://webdesigning.demon.co.uk
# Description:
# It stores the user's IP and the page he/she is browsing and counts how
# many visitors are currently visiting that page, displaying the number...
#
#################################################################################################
# Start of Configuration #
################################################################################################# */
$sql_host = "localhost"; //# The sql server hostname, usualy "localhost"
$sql_username = "username"; //# The username to the sql server
$sql_password = "password"; //# The password to the sql server
$sql_dbName = "databse_name"; //# The database in question
// CONNECT TO DATABASE //
$db_con = mysql_connect($sql_host, $sql_username, $sql_password)
OR die("<b><font color="red">Could not connect to MySQL server ($sql_host)...</b>\n<br>" . mysql_error() . "<br>Error @ line: " . __line__ . "</font>");
$db_select = mysql_select_db($sql_dbName)
OR die("<b><font color="red">Could not connect to the DATABASE ($sql_dbName)...</b>\n<br>" . mysql_error() . "<br>Error @ line: " . __line__ . "</font>");
// END OF DATABASE CONNECTION //
//========================================================================//
$timeoutseconds = 300; //# Timeout value in seconds
//# End of Configuration #
//#################################################################################################
$timestamp = time();
$timeout = ($timestamp-$timeoutseconds);
mysql_query("INSERT INTO useronline VALUES('$timestamp', '".$_SERVERї'REMOTE_ADDR']."', '".$_SERVERї'PHP_SELF']."')") or die("Useronline Database INSERT Error");
mysql_query("DELETE FROM useronline WHERE timestamp<$timeout") or die("Useronline Database DELETE Error");
$result = mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='$_SERVERїPHP_SELF]'") or die("Useronline Database SELECT Error");
$user = mysql_num_rows($result);
mysql_close();
if ($user==1) {
echo "$user User online";
}else {
echo "$user Users online";
}
?>