poker no more

Cocksure.
Good morning people! I’m happy right now because I’m writing the intro paragraph, which means this entry is almost done, and it’s only 9:30pm. Sharaun and I are doing the regular: she sits on the loveseat grading papers while I sit on the couch mucking with the laptop, all the while TiVo’d episodes of CSI play in the background. Come 10pm, she’ll head off to bed and I’ll move into the computer room where I can listen to tunes. Before that though, you can read this entry!

After a nice ride home, I turned on our electric fireplace and settled down with some cold pizza for some quality time with W. I was thinking how sucky it must be to be Cheney or Hastert and know your face will be in the shot of Bush during his entire speech. You can’t yawn or whisper or pass notes to your neighbor, you’d better applaud at the right time and look thoughtful or proud at the right time, and should laugh summarily at every joke. I also wonder how the network decided who’s face they’ll spotlight in on during certain parts of the speech. Is McCain asleep? Hillary digging at her nose? Get me tight on her face!

People who don’t care about behind-the-scenes blog technicalities can skip ahead.

For those who are interested in how I modified my StatTraq plugin to not log referrer spam, here ya go. I just added one more condition to the IF statement that enters a row into the stattraq database. This condition checks two things. First, does the referrer link contain a known spam keyword or spammer IP? Second, is the referrer link a query from a search engine? If the referrer link contains a known spam keyword or spammer IP, we don’t enter it in the database. The only exception being the case when someone is being referred to the site from a search engine where their search string contained a spam keyword. It amounts to something like this:

IF [(referrer does not contain known spam keyword AND referrer does not contain known spammer IP) OR referrer is from a search engine] THEN log referrer

I accomplish the OR referrer is from a search engine by searching for a question mark in the referrer string, since most search engine referrals have a “?” before the query string the user typed to get to your site. Today was the first day I ran StatTraq with the new conditionals, and I logged zero referrer spam links. Oh sure, since I don’t block spamferrers with .htaccess, they’re still in the main Apache logs, but I don’t care about that – I really only check stats for the blog. For those who’d like to do the same to their StatTraq, just replace the following line in stattraq.php (word-wrapped here, but will be a single line in the PHP file):

    if (!strstr($_SERVER['PHP_SELF'], 'wp-admin') && 
    !strstr($_SERVER['PHP_SELF'], 'wp-stattraq'))

With these (the IF statement is word-wrapped here, but make sure it’s just one long line in the PHP file):

    //grab modkeys from WP db
    $db_pattern = get_settings('moderation_keys'); 
    //create array on carriage return
    $db_pattern = explode("\n", $db_pattern); 
    //trim whitespace off all array elements
    $db_pattern = array_map('trim', $db_pattern); 
    //create long string with '|' separating elements
    $db_pattern = implode("|", $db_pattern); 

    if (!strstr($_SERVER['PHP_SELF'], 'wp-admin') && 
    !strstr($_SERVER['PHP_SELF'], 'wp-stattraq') && 
    ((!eregi($db_pattern, $referrer) && 
    !eregi($db_pattern, $ipAddress)) || ereg('\?', $referrer)))

The list of known spam referrers and spammer IPs is read right out of WP’s “moderation keys” option value for discussions. This is the list stored in the WP database which all comments are checked against before either going into the moderation queue or heading straight to the database. The great thing about using the WP moderation keys for the spam-compare string is that the keys are updated each time a new spammer is blocked using Kitten’s comment spam plugin. So, every time you kill a spam comment, its attributes are automagically added to the compare-string for stattraq entries. Exploiting the combination of WordPress and Kitten’s plugin serves to create the perfect spam-compare string; keeping 99% of comment-spam out of the WP database, and 99% of referrer-spam out of the stattraq database.

And, if you’re here reading about how to stop referrer spam from being logged in your stattraq table – that probably means you’ve already got some in there. So, after you’ve implemented the above code and blocked any new spam logging, you may want to go back and clean out any existing spam entries from your stattraq table. Luckily, the spam keywords list from above can be easily adapted into an SQL DELETE FROM statement which you can run on your stattraq table from within phpMyAdmin. For your reference, here’s the SQL statement:

click me for file

That should help cleanup the stattraq table a bit. I actually wish stattraq had some kind of “archive” or “clean” function built in, since that table can get really big really fast with all the search engine bot visits. Anyway, hopefully someone will find all this useful. (As an aside, do you know how friggin’ long it took me to figure out how to make that text file icon have no border and no link-underlining? Stylesheets are awesome, but can be a pain to override.)

And, before I get off the dev-talk, I’m pretty pumped about the upcoming new version of WordPress. Sounds like the UI is gonna be all new and cool looking, and the new “rel=nofollow” attribute thing will be rad too. Moving to WP as my blog software was the awesomest thing I coulda done.

Hey, non-technical-carin’ readers… we’re back to normal now.

Remember how I was gloating about getting my taxes done and filed so early? And, then, remember how I was saying it didn’t matter that I finished them so early, because I was confident I had all the data? Well, I got yet another 1098 in the mail today… some mortgage interest from a lender on my 2nd that I’d completely forgotten about since the refi. So… now I’m furiously amending my fed and state returns, to my windfall, granted, but still a pain. I guess, not only does the early bird get the worm – he also sometimes gets bitten for jumping the gun. And I was so satisfied that I was done with the whole mess. An amended tax return? What a blemish on my taxin’ skills. To ice the cake, now I’m afraid to file an amendment lest I get more stuff I don’t expect. Ugh.

I’m going to bed now, ‘night y’allz.


Also written on this day...

7 Replies to “poker no more”

  1. Hey great work on the referrer spam modification to stattraq – I really appreciate it.

    Trap for young players though: when I copied and pasted the snippet, PHP threw an error at first because there are ‘smart quotes’ in the if statement. I had to change them in a text editor to straight quotes.

    Otherwise it works perfectly.

  2. When I say word-wrapped i mean that the line is “broken up” for publishing purposes on the blog; but in the actual PHP file it will all be on one long line. Basically, your “IF” statment needs to be on one single long line, not broken up with carriage return(s) as I show in the post (I only did this so it would look “nicer” on the blog).

    Hope that helps.

  3. I use Referrer Karma which prevents referrer spammers from even downloading your page, thus saving bandwidth and processor time (apparently the author’s site actually went down because he was getting so much referrer spam).
    However, it does let some through, if it can’t reach the referrer site, but I’ve written a tiny modification to prevent stattraq logging this.

Leave a Reply

Your email address will not be published. Required fields are marked *