Jump to content
php.lv forumi

neliela online statistika.


alfinsh

Recommended Posts

Lūk ir mana online statistika, bet kkur ir kkas ne tā salikts. jo ja cilvēks ielogojās no 2 pārlūkiem lapā tad viņu tur rāda 2x ! Varētu kāds palīdzēt ? sorry ja ne tajā sadaļā!

 

<?php
if (!defined('BLOCK_FILE')) {
Header("Location: ../index.php");
exit;
}

global $CURUSER, $use_sessions, $tracker_lang;

$title_who = array();

$dt = sqlesc(time() - 300);

if (cache_check("online", 30) && cache_check("latest", 30)) {
$result = cache_read("online");
$a = cache_read("latest");
} else {
$a = mysql_fetch_array(sql_query("SELECT id, username FROM ".TABLE_USERS." WHERE status = 1 ORDER BY id DESC LIMIT 1"));

if ($use_sessions)
	$result = sql_query("SELECT s.uid, s.username, s.class FROM ".TABLE_SESSIONS." AS s WHERE s.time > $dt ORDER BY s.class DESC");
else
	$result = sql_query("SELECT u.id, u.username, u.class FROM ".TABLE_USERS." AS u WHERE u.last_access > ".sqlesc(get_date_time(time() - 300))." ORDER BY u.class DESC");

$online_cache = array();
while ($cache_data = mysql_fetch_array($result))
	$online_cache[] = $cache_data;

cache_write("online", $online_cache);
cache_write("latest", $a);
$result = $online_cache;
}

if ($CURUSER)
$latestuser = "<a href=userdetails.php?id=" . $a["id"] . " class=\"online\">" . $a["username"] . "</a>";
else
$latestuser = $a["username"];

foreach ($result as $arr) {
list($uid, $uname, $class) = $arr;

   if (!empty($uname)) {
   	$title_who[] = "<a href=\"userdetails.php?id=".$uid."\" class=\"online\">".get_user_class_color($class, $uname)."</a>";
   }

   if ($class >= UC_MODERATOR) {
   	$staff++;
} elseif (empty($uname)) {
   	$guests++;
   } elseif ($class < UC_MODERATOR) {
   	$users++;
   }

   $total++;

if (empty($uname))
	continue;
else
	$who_online .= $title_who;

}

if ($staff == "")  $staff = 0;
if ($guests == "") $guests = 0;
if ($users == "")  $users = 0;
if ($total == "")  $total = 0;

$content .= "<table border=\"0\" width=\"100%\"><tr valign=\"middle\"><td align=\"left\" class=\"embedded\"><b>".$tracker_lang['Latest'].": $latestuser<hr></td></tr></table>\n";

if (count($title_who)) {
$content .= "<table border=\"0\" width=\"100%\"><tr valign=\"middle\"><td align=\"left\" class=\"embedded\"><b><font color=green>".$tracker_lang['total'].": [$total]</font> <font color=gray>".$tracker_lang['Viesi'].": <b>[$guests]</b></font></b><hr></td></tr><tr><td class=\"embedded\">".@implode(", ", $title_who)."<hr></td></tr></table>\n";
} else {
$content .= "<table border=\"0\" width=\"100%\"><tr valign=\"middle\"><td align=\"left\" class=\"embedded\"><b>Źņī īķėąéķ: </b>Nav aktivitātes pēdējās 10 minūtes.<hr></td></tr></table>\n";
}

  ?>

Link to comment
Share on other sites

×
×
  • Create New...