If you are running a site that is powered by Drupal you might want to take some precautions against spam being posted to your site, particularly if you allow comments. A useful way to stop such automated submissions is to use the reCaptcha system which allows you to generate a CAPTCHA and help digitise books at the same time. This whole system can be integrated into Drupal easily using the recaptcha module. This works really well unless your web server is behind a proxy server for web requests.
The modules in their supplied form do not work in this situation, but can be modified. This is a major strength of open source - if it doesn't work you can fix it. Here I will present what worked for me, there may be better methods, if so feel free to comment. The first thing to do is ensure that your Drupal installation can cope with a proxy, have a look at: http://drupal.org/node/7881 for more information on that.
Install the recaptcha module as directed in the instructions. When you enable the module and enter your API keys, you will notice that a match captcha is displayed instead of the recaptcha plug in. This is because the module tests that the recaptcha server is available, if not it falls back to the math captcha. This test does not work behind a proxy. To make it work open up the recaptcha.module file and look for the comment that reads:
// Check if reCAPTCHA is available and show Math if not
Comment out these lines:
$connect = @fsockopen(RECAPTCHA_VERIFY_SERVER, 80);
if (!$connect) {
Now we will add a couple of lines to use your new proxy enabled Drupal to make this check:
$response = drupal_http_request('http://'.RECAPTCHA_VERIFY_SERVER, array(), 'HEAD');
// if a 5xx HTTP code returned then fall back on math captcha
if ($response->code >= 500) {
The API returs a 404 status if you do not provide it with any data. This is normal, so we just check for server errors.
Now comment out the end of the old check:
fclose($connect); // close connection
We are half way there! As part of the installation procedure you will have obtained a file named recaptchalib.php. We need to make some changes to make this direct its requests through a proxy:
Find the function named _recaptcha_http_post() and comment out this line:
$http_request = "POST $path HTTP/1.0\r\n";
Now add this line beneath it:
$http_request = "POST http://".$host.":".$port.$path." HTTP/1.1\r\n";
To finish off the new request comment out this line:
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
..and add this below it:
if( false == ( $fs = @fsockopen("YOUR PROXY HOST", "YOUR PROXY PORT", $errno, $errstr, 15) ) ) {
Hopefully you should now be able to take full advantage of the reCaptcha system!
Blogged with Flock
Re: reCaptcha, Drupal and a Proxy: A way to make it all work tog
I found this page by googling 'recaptcha' and 'proxy' having struggled to make recaptcha work from behind a proxy (and finding the recaptcha support forum somewhat lacking in detail).
I'd just like to say a big *thank you* because even though I don't use Drupal applying the modifications you describe to the library file mean my implementation now works fine.
Re: reCaptcha, Drupal and a Proxy: A way to make it all work tog
ReCaptcha is a good captcha program but it can be hard to set up with a proxy. Thanks to you, we have an easy solution. Thank you for your help. I still can't believe that recaptcha helps digitize books, it is so cool.
Re: reCaptcha, Drupal and a Proxy: A way to make it all work tog
I think this is a great idea. I had been interested in the whole idea of digitizing out of print/copyright books after coming across an old library of books which my grand father used to own.
Its a great resource for everyone to use and I'm sure the authors would be proud
Re: reCaptcha, Drupal and a Proxy: A way to make it all work tog
Thanks for this, exactly what I was looking for. You have solved a big headache for me.
Nice tutorial
Drupal has so many interesting features but its needs some serious learning. A good tutorial to work out captcha, just bookmarked it for reference.
Donna
Re: reCaptcha, Drupal and a Proxy:
I'm still developing in Joomla, I've been researching other options and I've found some good stuff about Drupal... Thanks for the info!
Nice tips. Will keep them in
Nice tips. Will keep them in mind.
I had been interested in the
I had been interested in the whole idea of digitizing out of print/copyright books after coming across an old library of books which my grand father used to own.
Re: reCaptcha, Drupal and a Proxy: A way to make it all work tog
Looks like a bit of a task to get through but cool just the same!