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.
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.
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.
<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
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!
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''image_iframe''<iframe>'-elements for image-captchas. In case of text-captcha this will produce the same output as 'image'.
'input''text'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.
There is no way to reload a Text-Captcha. It will be reloaded automatically after a wrong or missing input, though.
The constant CAPTCHA_TYPE tells which captcha-type is actually used.
ttf_imagecalc_ttf_imagecalc_textcalc_imageold_imagetext
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.
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:
| new CAPTCHA | 0 Comments |