Click here to Skip to main content
Click here to Skip to main content

How To : Using Phpbb3 CAPTCHA

By , 12 Feb 2009
 
phpbb captcha

Introduction

Phpbb3 uses a powerful captcha class that is created by Xore (Robert Hetzler). We really thank him for this work. Thank you Robert.
We can use this class in our project with GNU Public License.
This article tells us how we can change its configuration and use it.

How To : Using Phpbb3 Captcha

Generating Random Expressions

First I wrote a PHP class for generating random expressions. (DayyanRandomCharacters)
Below is a sample:

include_once("include/DayyanRandomCharactersClass.php");
$DayyanRandomCharacters = new DayyanRandomCharacters();
  $id = $DayyanRandomCharacters -> get_id();
  $key = $DayyanRandomCharacters -> get_key();
  $Code = $DayyanRandomCharacters -> get_code();
$ConfirmString = strtoupper($DayyanRandomCharacters -> md5_decrypt($id, $key));
$ConfirmString = substr($ConfirmString, 0, 6);
echo '$id=' . $id . '<br />';
echo '$key=' . $key . '<br />';
echo '$Code=' . $Code . '<br />';
echo '$ConfirmString=' . $ConfirmString . '<br />';

Phpbb3 Captcha Classes

I used captcha_gd.php file , you can find it in phpBB3\includes\captcha\ folder.
There are three classes in this file:

  1. captcha
  2. char_cube3d
  3. colour_manager

captcha class has a function with name execute, we must use it.
Signature of the execute function is as follows:

function execute($code, $seed)

At the end of this function, we see these expressions:

header('Content-Type: image/png');
header('Cache-control: no-cache, no-store');

I disabled them because I wanted to change the way of showing captcha image.
If you would like to show captcha image directly by execute function, you must enable them.

Captcha Image's Size

There are two variables in the beginning of captcha class that we can change of the image's size.
var $width = 360;
var $height = 96;

Configurations

There is a global array ($config) in Phpbb3 captcha to changing configurations.
Samples:

//Configurations of PHPBB3 captcha
$config = array('captcha_gd_x_grid' => false,
        'captcha_gd_y_grid' => false,
        'captcha_gd_foreground_noise' => false);

Result of the above configurations is as shown below:

phpbb captcha

$config = array('captcha_gd_x_grid' => false,
        'captcha_gd_y_grid' => false,
        'captcha_gd_foreground_noise' => true);

Result of the above configurations is as shown below:

phpbb captcha

$config = array('captcha_gd_x_grid' => false,
        'captcha_gd_y_grid' => true,
        'captcha_gd_foreground_noise' => false);

Result of the above configurations is as shown below:

phpbb captcha

$config = array('captcha_gd_x_grid' => true,
        'captcha_gd_y_grid' => false,
        'captcha_gd_foreground_noise' => false);

Result of the above configurations is as shown below:

phpbb captcha

Using the Code

Now we can use Phpbb3 captcha easily, something like this:

<?php
include_once("include/DayyanRandomCharactersClass.php");
$DayyanRandomCharacters = new DayyanRandomCharacters();
  $id = $DayyanRandomCharacters -> get_id();
  $key = $DayyanRandomCharacters -> get_key();
  $Code = $DayyanRandomCharacters -> get_code();
?>
<img src="include/?id=<?php echo $id; ?>&amp;key=<?php echo $key; ?>" 
    alt="<?php echo $Code ?>" title="<?php echo $Code ?>" 
    name="phpbb3Captcha" border="0" id="phpbb3Captcha" />
<br /><br />
<input name="Code" type="text" id="Code" value="<?php echo $Code ?>" />

For more information, see the source code attached to this article.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Mohammad Dayyan
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralVery good articlememberparmando17 Feb '09 - 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 12 Feb 2009
Article Copyright 2008 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid