new CAPTCHA

In Website Baker 2.7 there was introduced a new Captcha, including a new Image-Captcha, a Math-Captcha, and a Question/Answer-Captcha.

Additionally there is a new Admin-Tool to choose which kind of Captcha to use.

HowTo

How to use the new Captcha in a module.

We assume two files, view.php which will include the captcha, and save.php which will receive the form's data and will check the captcha.

view.php

To use the captcha, we have to include the file wb/include/captcha/captcha.php into our view.php

require_once(WB_PATH.'/include/captcha/captcha.php');

To display the Captcha, we call the function call_captcha();

call_captcha();
// The captcha-value is now stored in $_SESSION['captcha']

This function stores the captcha-value into $_SESSION['captcha'], and prints the following html for all image-captchas.

Output

<table class="captcha_table">
<tr>
<td class="image_captcha">
  <iframe class="captcha_iframe" width="140" height="40" scrolling="no" marginheight="0"
          marginwidth="0" frameborder="0" name="captcha_iframe"
          src="http://example.org/include/captcha/captcha.php?display_captcha=1">
    <img src="http://example.org/include/captcha/captchas/ttf_image.php?t=1987654321" alt="Captcha" />
  </iframe>
</td>
<td></td>
<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
<td class="captcha_expl">Please enter Text</td>
</tr>
</table>

Text-Captchas won't have an <iframe>-element.

The <iframe> itself will display

Output

<a href="http://example.org/include/captcha/captcha.php?display_captcha=2">
<img alt="Captcha" src="http://example.org/include/captcha/captchas/ttf_image.php?t=1987654321"
     style="border: none;" />
</a>

save.php

The captcha is received in $_POST['captcha'], and we need to check it against $_SESSION['captcha'].

if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha']==''
   OR $_POST['captcha']!=$_SESSION['captcha']) {
  // captcha failed - back to form
}
// captcha ok - continue

That's all!


call_captcha()

Instead of letting call_captcha() print the whole captcha-table at once, one may use two parameters to alter the output:

call_captcha('action', 'style');

'style' may hold a css-style. If 'style' is present, each STYLE in the next examples will be replaced by 'style'.

Possible values for 'action':

'image'
just prints the image
<img STYLE src="http://www.../include/captcha/captchas/CAPTCHA_TYPE.php?t=1234567" />

or text (depends on captcha type)

<span STYLE>7 add 3</span>

'image_iframe'
prints the '<iframe>'-elements for image-captchas. In case of text-captcha this will produce the same output as 'image'.
'input'
prints the input-field

<input type="text" name="captcha" STYLE />

or without 'style'

<input type="text" name="captcha" style="width:20px;" maxlength="10" />

'text'
prints a language-dependant string

<span STYLE>Fill in the result</span>

reload Captcha

Image Captcha

One may reload the Captcha (if the actual one isn't readable) through a click on the Captcha itself or on the red reload button associated with each Captcha.

Text Captcha

There is no way to reload a Text-Captcha. It will be reloaded automatically after a wrong or missing input, though.

determining Captcha Type

The constant CAPTCHA_TYPE tells which captcha-type is actually used.

ttf_image

new image-captcha with 5 chars/numbers.

Captcha in wb 2.7Captcha in wb 2.8

calc_ttf_image
new image-captcha with calculation
calc_text
calculation as text.
calc_image
the old image-captcha with calculation.
old_image

the old image-captcha type. Do not use this anymore!

old Captcha

text
the question/answer-captcha. This type is problematic (see below).

Customisation

new Image-Captcha

To customise the new image-captchas, one may copy new backgrounds (140×40, .png only) to wb/include/captcha/backgrounds. The file name doesn't matter. One may also copy new fonts (.ttf only) to wb/include/captcha/fonts.

Text-Captcha

To use the Question/Answer-Captcha, one has to add question/answer-pairs to the textarea in the Admin-Tool.

Use exactly two lines per answer/question. Prepend each question with a ?, and each answer with a !.

?What's Claudia Schiffer's first name?
!Claudia
?What's the background colour of this page?
!white
#all other lines are considered comments

In an multi-language environment one may add additionally a language-marker (e.g. EN:):

?EN:What's Claudia Schiffer's first name?
!Claudia
?EN:What's the background colour of this page?
!white
?DE:Marias Mutter hat fünf Töchter: Nana, Nene, Nini, Nono, ... Wie heißt die Fünfte?
!Maria

But this Captcha type is very problematic:

  • currently this captcha is case sensitive!
  • it can't handle different spelling (e.g. “weiß” or “weiss” in german which means both the same).
  • it may be very frustrating for the user if he can't solve such captchas.

new CAPTCHA 0 Comments
 
projects/new_captcha/start.txt · Last modified: 2010-05-30 16:30 by Thomas "thorn" Hornik
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki