Monday, March 02, 2009

Keeping the spammers out

If you do anything on the web that allows people to post comments, such as a guest book or a forum, then the biggest headache is keeping out the vermin who add unwanted contributions linking to sites selling pharmaceuticals and other wares. As radio amateurs there are ways at our disposal to obstruct such unwanted comments. For example, asking a question like "What band is 14.100MHz in?" or "What is the Q code for 'low power'?" would defeat most non-hams. But this isn't often used, probably because most people use standard packages and don't know how to hack the code to add such a question.

I'm currently working on a new ham radio website which I can't say anything about yet (hence the infrequency of blog postings at the moment.) This site will require people to register in order to access the interactive pages, and I wanted to not only keep the spammers out, but also ensure that amateurs register using their callsigns.

Thanks to phant0m and nrg_alpha over at PHP Freaks Forums, I now have a nice little PHP function that checks whether the supplied argument looks like a valid callsign.
<?php
// function to check if argument is in format of a valid callsign
function valid_call($callsign){
return preg_match('=^\d?[a-z]{1,2}\d{1,4}[a-z]{1,3}$=i', $callsign);
}
?>
(Note that I did not require the function to accept prefixes like F/G4ILO or G4ILO/P.)

You still have to figure out how to call it from your forum software, guest book script or whatever, but hopefully some will find it useful.
Post a Comment