I've Been Watching You
September 12th, 2004
A few weeks ago I quietly added a statistical tracking feature to the site, and since have been keeping a very close eye on you. I know when you visit my site, how many times you have visited, what kind of browser you use, and even what language you speak. All of this was made possible by a nifty little app from Shaun Inman called ShortStat, and a few hacks from Janne Kalliola and Matthew Pennell.
Now that a had a while to play around and tweak the look of ShortStat to fit in with the site, I'm letting you in on all of the exciting stat-viewing action from the stats page. I'll soon be adding a permanent link from the About page so keep a eye out for it. Until then, I hope the anticipation doesn't give you a heart attack.
Hacks I've implemented:
- Recent and repeat visitors in ShortStat
- Shortstat improvements
- Filtering my own visits from Shortstat
Site News | Comments (11) | words in this post
Comments
More Entries Like This
- New Feature
7:42 PM Jan 21, 2003
Very nice stats page, I like the idea of integrating the stats in the normal layout of the site.
One catch though, ShortStat does not allow you to create links to it. If it founds out that there is a HTTP REFERER in the request, it'll automatically redirect the request to the site home page. So you don't see the stats by following the link, but instead you have to write the link URL to the browser location field.
This feature is for disabling referer spamming, i.e. getting better ranks in Google by submitting your site as an HTTP referer to public stat pages.
I was wondering whether I should change the behaviour so that you could make links from your own site to the stats and the stats would turn down all robotic approaches to read its contents. Any interest?
I didn't even try it out (the link), thanks for letting me know it didn't work. I just tried out two different ways around the problem.
First was a javascript link:
<a href="JavaScript:open('/stats/')">stats</a>but it was ugly and I didn't like spawning a new window to make it work
Next I commented out:
if (!empty($_SERVER['HTTP_REFERER']) && $_POST['MP_shortstat_check'] != "yes") { header("Location:http://$_SERVER[SERVER_NAME]"); }but now I'm open to referrer spam
I would love to see an option in the configuration file to have a link "whitelist". However, I hope it would be available as a patch because I've modified ShortStat so much that I will never be able to upgrade.
i clicked on lots of the recent viewers and the first 10 big repeaters, and none of them are us. but i know i've gone to your website at least that many times. when did the counting begin? and the recent viewers show times i looked today, but not any address in austin. how is the tracking working?
T. Your right there 68.201.191.92 - cs68201191-92.austin.rr.com
37 visits since the count started 21 Aug 2004 @ 4:05 pm
Who's doing the most recent comments? Apparently, you're attracting spammers. You must be very popular.
I addressed the issue that Janne refers to by simply adding an additional check to the line dclal quotes:
if (!empty($_SERVER['HTTP_REFERER']) && $_POST['MP_shortstat_check'] != "yes") { header("Location:http://$_SERVER[SERVER_NAME]"); }I added a check for whether the HTTP_REFERER string contained the name of my site - therefore permitting direct links from my site, but not from anyone else's.
This check could be performed with the following PHP code (not tested, just written from top of my head):
$allow = 'http://' . $_SERVER['SERVER_NAME'];if((!empty($_SERVER['HTTP_REFERER'] &&
strncasecmp($_SERVER['HTTP_REFERER'], $allow, strlen($allow)) &&
$_POST['MP_shortstat_check'] != "yes") {
header("Location:http://$_SERVER[SERVER_NAME]");
}
Thanks Janne, but the code didn't seem to work. Im getting a parse error
Parse error: parse error, unexpected T_BOOLEAN_AND, expecting ')' in /.../stats/index.php on line 18Which reads (line 18)
if((!empty($_SERVER['HTTP_REFERER'] &&I've taken a stab at changing the code a bit, but my php is not as good as my html.
I appreciate the effort though.
Okay, let's try again. The problem is with unbalanced brackets. I added one after the empty check (to close the function call) and another after strncasecmp (to close the condition (not empty and not own)). I also added != 0 for the strncasecmp to make thing work better. Hopefully this helps -- but remember that this isn't tested either.
$allow = 'http://' . $_SERVER['SERVER_NAME'];if((!empty($_SERVER['HTTP_REFERER']) &&
strncasecmp($_SERVER['HTTP_REFERER'], $allow, strlen($allow)) != 0) &&
$_POST['MP_shortstat_check'] != "yes") {
header("Location:http://$_SERVER[SERVER_NAME]");
}
Thanks Janne. That seems to do it. I had to turn off my RewriteRule in .htaccess to get it working though.
RewriteEngine OnRewriteCond %{HTTP_HOST} ^www.dclal.com$ [NC]
RewriteRule ^(.*)$ http://dclal.com/$1 [R=301,L]
I guess I am no longer a "Class B" site.
A great bonus would be a "whitelist" for approved sites, but beggars can't be choosers.
I got it! Using Janne's code with a little modification.
$allow = 'http://dclal.com';$allow = 'http://www.dclal.com';
if((!empty($_SERVER['HTTP_REFERER']) &&
strncasecmp($_SERVER['HTTP_REFERER'], $allow, strlen($allow)) != 0) &&
$_POST['MP_shortstat_check'] != "yes") {
header("Location:http://$_SERVER[SERVER_NAME]");
}
It's not as pretty as a whitelist, but it does the trick for now.