|
|
Issue 2 [ 3/2004 ] |
Biotechnology, Bioinformatics |
|
|
|
// CONFIGURATION
$db_visitors = "visitors";
$db_username = "mysql";
$db_password = "mysql";
$db_database = "elearning";
$db_hostname = "libmod3.lib.kmutt.ac.th";
// CONNECT TO MYSQL DATABASE
@mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database);
function UpdateVisitors()
{
session_start();
if(!isset($_SESSION['visits']))
{
mysql_query("UPDATE ".$GLOBALS['db_visitors']." SET visits_em=visits_em+1");
$_SESSION['visits'] = 1;
}
else
$_SESSION['visits']++;
mysql_query("UPDATE ".$GLOBALS['db_visitors']." SET pageviews_em=pageviews_em+1");
}
function ShowVisitors()
{
$result = mysql_query("SELECT * FROM ".$GLOBALS['db_visitors']);
$ar = mysql_fetch_array($result);
$ret[0] = $ar[visits_em];
$ret[1] = $ar[pageviews_em];
return $ret;
}
// EXAMPLE: HOW TO USE
UpdateVisitors(); // Update statistics
$stats = ShowVisitors(); // Get statistics from database and store it into array $stats
?>
echo "Visitors:".$stats[0]; // Show $stats[0] array (visitors value)
echo " ";
echo "Pageviews:".$stats[1]; // Show $stats[1] array (pageviews value)
?>
Presented by
Digital Library Team | e-mmet@lib.kmutt.ac.th
|
|
|