Skip to content

Instantly share code, notes, and snippets.

@Kaivosukeltaja
Last active January 21, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kaivosukeltaja/62e0cb98e8db16474e557d829975c659 to your computer and use it in GitHub Desktop.
Save Kaivosukeltaja/62e0cb98e8db16474e557d829975c659 to your computer and use it in GitHub Desktop.
Mikseri.net profile page visitor counter
/* == PAGECOUNTER == */
/* == Pitää lukua päivittäisistä vierailijamääristä == */
$pagecounter_cache_key = 'pagecounter_' . $user_id . '_' . date('Y-m-d');
$pagecounter = $cache->get($pagecounter_cache_key);
if (!is_array($pagecounter))
{
$pagecounter = array();
$res = $db->query("SELECT date, count from pagecounter WHERE WEEK(date) = WEEK(CURDATE()) AND user_id = ?", array($user_id));
if ($res->numRows() > 0)
{
foreach($res as $item)
{
$pagecounter[$item['date']] = $item['count'];
}
}
if(!isset($pagecounter[date('Y-m-d')]))
{
$db->query("INSERT INTO pagecounter SET date = curdate(), user_id = ?", array($user_id));
$pagecounter[date('Y-m-d')] = 0;
}
}
if ($user_id != $myid or rand(1, 10) == 1)
{
$pagecounter[date('Y-m-d')]++;
$db->query("UPDATE pagecounter SET count = ? WHERE date = CURDATE() AND user_id = ? LIMIT 1", array($pagecounter[date('Y-m-d')], $user_id));
}
$cache->set($pagecounter_cache_key, $pagecounter, 3600);
$smarty->assign('pagecounter', $pagecounter);
/*
mysql> describe pagecounter;
+---------+------------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+------------+-------+
| date | date | NO | MUL | 0000-00-00 | |
| user_id | int(10) unsigned | NO | | 0 | |
| count | int(10) unsigned | NO | MUL | 0 | |
+---------+------------------+------+-----+------------+-------+
3 rows in set (0.01 sec)
*/
{if $userdata.id == $thisuser.id}
<br />
Profiilia katsottu tällä viikolla {$pagecounter|@array_sum} <span class="light">(näkyy vain itselle)</span>
{/if}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment