Ravaged by Robots!
By Randal L. Schwartz
In last month's column, I talked about implementing one type of survey form for customer feedback. Other types of forms often have ratings systems or multiple-choice values, which are then summarized into an average score to determine the most frequent responses.
Of course, such forms are meant to be used only once per person. But what if some of your responses are coming from Web robots? A clever Perl hacker could write a ballot stuffing program with just a few lines of code.
I was actually thinking about this problem the other day. As a human, it's trivial for me to see an image, extract the text content, and type it back into a form element. On the other hand, that has to be reasonably difficult for an automated form submission robot! That got me scurrying off to figure out how to validate a form using an image. After a couple of false starts, I came up with the program presented in
Listing 1, as a demonstration of this technique's basics.
Lines 1 through 3 are my standard Perl program header, enabling warnings, compiler restrictions, and disabling the buffering of STDOUT. Line 5 brings in all of the CGI shortcuts as functions rather than methods.
Lines 7 through 13 give our program a bit of memory using the Cache::Cache module subclass, Cache::FileCache. The Cache::Cache suite is found in the CPAN, and is being actively developed by DeWitt Clinton.
Here, we're setting up a cache that remembers things for ten minutes.