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:
captcha
char_cube3d
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:
$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:
$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:
$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:
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; ?>&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.