Feature request: A bit of code displaying amount of hits

2 views
Skip to first unread message

mr.riff (itch.in)

unread,
Jan 2, 2006, 5:10:26 PM1/2/06
to SlimStat
I was wondering if I could a put in a feature request.

I'd love to have a bit a code that'd display amount of hits in a given
time (day, week, month, forever) that I'd be able to display on any
page on my site.

I'm sure this shouldn't be too hard to do, it's something like a hit
counter that pulls its info from slimstat's database. I wouldn't mind
it being a simple php include either.

Cheers,
Arif.

Stephen Wettone

unread,
Jan 10, 2006, 10:08:26 AM1/10/06
to slim...@googlegroups.com
On 2 Jan 2006, at 22:10, mr.riff (itch.in) wrote:
> I'd love to have a bit a code that'd display amount of hits in a given
> time (day, week, month, forever) that I'd be able to display on any
> page on my site.
>
> I'm sure this shouldn't be too hard to do, it's something like a hit
> counter that pulls its info from slimstat's database. I wouldn't mind
> it being a simple php include either.

This is an excellent idea! It's fairly simple to do at the moment,
but you're right, a one-line include would be nice.

Here's how to do it with SlimStat 0.8. Please note that the API may
change between here and 1.0.

First, include SlimStat's functions, like so:

include( $_SERVER["DOCUMENT_ROOT"]."/slimstat/_functions.php" );

Then call the get_hits_visits_uniques() function, where the first
parameter is the SQL to be inserted in the WHERE clause of the query:

$hvu = SlimStat::get_hits_visits_uniques
( "resource='".SlimStat::my_esc( $_SERVER["REQUEST_URI"] )."'" );

You will now have an associative array, with which you can do
whatever you like:

print_r( $hvu );

Note that "visits" and "uniques" are only supplied if the
corresponding $show_visits and $show_uniques variables are set to
true in SlimStat's _config.php.

To get data for different time periods, just add more SQL. For
example, here's how to get data for today:

$hvu = SlimStat::get_hits_visits_uniques
( "resource='".SlimStat::my_esc( $_SERVER["REQUEST_URI"] )."' AND
dt>".mktime( 0, 0, 0 ) );

I think it's fairly easy to make an includable file that would output
something like the Summary module. It could borrow most of the code
from _summary.php and just add the resource.


Stephen

Reply all
Reply to author
Forward
0 new messages