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.

2 comments:

Anonymous said...

Julian,
I have two different Ham Radio Forums running(one is new)and I am forced to delete many registered users posting SPAM, PORN and various objectionable material. I am running vBulletin just like QRZ.com, so I would bet someone has added your PHP script to it. Just wondered if you would know how I might find hese instructions. I need this protection bad to keep out the rif raf, Thanks

Jerry - NF9L NF9L@arrl.net

http://K0GQ.com/forums

http://KCHamRadio.com

Unknown said...

I don't know anything about vBulletin, Jerry, but I would guess that it has a support forum so I think the best place to ask would be there. You could also try asking Fred, AA7BQ, who runs QRZ.com. If he has done it, he might not mind telling you.