Hi!

I wanted to restrict the access of a certain node (a page, my contact information) to human visitors. I found a way to do this with CAPTCHA. The content of the node is wrapped into some PHP code that shows an almost empty form before the user has proven his human nature, and the real content otherwise. This form becomes a CAPTCHA point. Maybe someone else can use this idea, or even develop it a bit further. The code can probably be improved, maybe there's a better way to do that, or you guys could integrate this feature to your module.

Here's the code:

<?php
# Check whether user needs a CAPTCH
# (he does if he doesn't have the skip CAPTCHA permission or if he hasn't answered a CAPTCHA yet)
$passedCaptcha = user_access('skip CAPTCHA') ||
      _captcha_persistence_skip('empty_captcha_form') ||
      $_SESSION['captcha']['success'];

# Defines an almost empty form just to be able to create a captcha point
# see http://api.drupal.org/api/drupal/developer--topics--forms_api.html/5
if( !function_exists( empty_captcha_form ) ) {
  function empty_captcha_form() {
    $form['submit'] = array('#type' => 'submit', '#value' => t('Validate'));
    return $form;
  }
}

# Display form is user hasn't validated a captcha yet, the real content otherwise
if( !$passedCaptcha ){
  echo "<br><h2>This page is only accessible for human beings!</h2>\n";
  echo "Please fill out the form below in order to prove that you're human and to gain access to the real content of this page.<br>\n";
  return drupal_get_form('empty_captcha_form');
} else {
?>

real content of the node!!

<?php } /* end of captcha test */ ?>

After that, create a CAPTCHA point in the admin menu for the menu id "empty_captcha_form". That should be it!

Comments welcome!

Ingo

Comments

bluesband’s picture

this code not working for my Drupal installation.

subscribing !

iantresman’s picture

Unfortunately the snippet is giving me the following error message:

Fatal error: Call to undefined function _captcha_persistence_skip() in /includes/common.inc(1695) : eval()'d code on line 7

It seems that the function "_captcha_persistence_skip" was removed in later versions of CAPTCHA.

Any suggestions? I'm running CAPTCHA v6.x-2.2 with Captcha Riddler 6.x-1.1

iantresman’s picture

Anyone know whether the snippet above can be converted for use with CAPTCHA v6.x-2.2? I tried to figure it out myself, but it's beyond my ability.

Updated 8 Nov 2010: I may have worked this out. See my post here.

elachlan’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)