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:

Comments

  1. Janne Kalliola
    September 12, 2004 12:31 PM

    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?

  2. dclal
    September 12, 2004 03:26 PM

    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.

  3. tara
    September 12, 2004 06:13 PM

    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?

  4. dclal
    September 12, 2004 07:00 PM

    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

  5. Teresa
    September 19, 2004 12:05 AM

    Who's doing the most recent comments? Apparently, you're attracting spammers. You must be very popular.

  6. Matthew Pennell
    September 21, 2004 03:51 AM

    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.

  7. Janne Kalliola
    September 23, 2004 02:40 PM

    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]");
    }

  8. dclal
    September 25, 2004 10:56 AM

    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 18

    Which 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.

  9. Janne Kalliola
    September 26, 2004 10:54 AM

    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]");
    }

  10. dclal
    September 26, 2004 11:38 AM

    Thanks Janne. That seems to do it. I had to turn off my RewriteRule in .htaccess to get it working though.

    RewriteEngine On
    RewriteCond %{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.

  11. dclal
    September 26, 2004 12:06 PM

    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.

Comments

Post a Comment


 
 

Feel free to use: <b> | <strong> | <em> | <a href=" "> | <p> | <br ⁄> | <li> | <code> | <blockquote>

Preview

Subscribe?

Check Subscribe to be notified each time a coment is posted to this entry.

Your email must be filled in above to subscribe.

Remember Me?

Check Yes to have me fill in your information each time you log in.

 
   

More Entries Like This