Show MT-Blacklist 2 stats on your blog.
So, just because I like to rub it in the face os spammers, I have added a section to the right that will report some stats on what MT-Blacklist v2.01b running on Moveable Type 3.11 has blocked to date.
This information is available to you in the MT-Blacklist interface, but I just wanted to move it out here and show it on my blog…because…well…I like to look at numbers as they grow, and know in my heart of hearts that each time it increases, a spammer is wasting it’s time with me.
I have included the PHP code that I wrote in the extended entry if anyone else wants to use it. Be forewarned, I am not a super l33t PHP/MySQL programmer, but the code works for me. I have tested it on nothing else aside from my installation, using the versions of the programs mentioned above.
I might be able to help you if you have a problem, but I offer no guarantees.
Don’t bother writing and telling me I write messy or crap code, because well…I don’t much care. But if you have constructive critisism, that’s ok.
10/19/2004 – *Updated slightly based on Mike C’s suggestions, nothing major, just cleaned up a bit*
<?php
$dbserver="localhost"; // Quite likely localhost
$dbname="dbname"; // name of your moveable type mysql database
$dbusername="username"; // Database username
$dbpass="password"; // Database password// You should not need to edit anything below this line
if (!mysql_connect($dbserver, $dbusername, $dbpass)) {
die(‘Could not connect: ‘ . mysql_error());
}if (!mysql_select_db($dbname)) {
die (‘Can\’t use $dbname : ‘ . mysql_error());
}$result = mysql_query("SELECT * FROM mt_ext_bl_item");
$num_rows = mysql_num_rows($result);echo "<b>$num_rows</b> items in Blacklist <br />";
$result = mysql_query(‘SELECT * ‘
. ‘ FROM `mt_ext_bl_group` LIMIT 0, 30′);
if (!$result) {
die(‘Could not query:’ . mysql_error());
}$getdata = mysql_fetch_array($result);
echo ‘<b>’.$getdata["ext_bl_group_blocked_count"].’</b> Comment Spams Blocked
‘.’<br />’
.’<b>’.$getdata["ext_bl_group_moderated_count"].’</b> Comment Spams Moderated
‘.’<br />’
.’With <a href="http://www.jayallen.org/comment_spam/">MT-Blacklist v2.01b</a>’;mysql_free_result($result);
mysql_close($link);
?>
By laura, October 6, 2004 @ 9:22 am
oh man, you’re such a nerd.
By SMooSH, October 6, 2004 @ 9:41 am
It’s true….
You’re jealous…
By Rogi, October 6, 2004 @ 3:42 pm
I would say that was quite nifty, but saying that would risk me getting an undeserved (in my case, not yours) Nerd label as well.
So…
“That bit of code is just a little tiny bit interesting, SMooSH.”
By Mike C, October 15, 2004 @ 8:04 pm
Matt,
I know you might hate taking hints from your nephew… but a couple things
There are some variables there you keep around that you don’t need to. IE: $link, $db_selected. Sort of adds clutter to the whole script.
It could just as easily be done:
if (!mysql_connect($user, $pass, $host))
{
die(‘blah’);
}
if (!mysql_select_db($db))
{
die(‘blah’);
}
The link variable doesn’t need to be carried around unless you plan to connect to another DB in the same script. mysql_query will always use the last link used, unless otherwise specified.
mysql_free_result and mysql_close are totally unecessary as well, since connections are closed at the end of script execution unless you create persistant connectoin.
Other than that… looks good. Double quotes ARE your friend though, no need to break out of a string as often… “Hi $name” rather than ‘Hi ‘ . $name…
That’s about it!
By SMooSH, October 16, 2004 @ 9:41 am
Din’t mind taking hints from my nephew at all.
You’re better at this stuff than I will likely ever be
Thanks!
I always forget about that double quote vs single quote thing…
By maird, October 23, 2004 @ 8:27 am
one more quick tip for you:
instead of
$result = mysql_query(“SELECT * FROM mt_ext_bl_item”);
$num_rows = mysql_num_rows($result);
echo “$num_rows items in Blacklist “;
you could do
$result = mysql_query(“SELECT count(*) FROM mt_ext_bl_item”);
echo “$result[0] items in Blacklist “;
it’ll make the query faster and use less memory cause it doesn’t need to return the whole table just to count the number of rows…
By ***Dave Does the Blog, October 26, 2004 @ 11:46 am
Rubbing their noses in it
Nifty little bit of PHP code here to show your MT-Blacklist stats on the front page of your blog. Probably not going to do it myself, but thought it worth…