Click here to Skip to main content
Click here to Skip to main content
Go to top

How To : Using Phpbb3 CAPTCHA

, 12 Feb 2009
Rate this:
Please Sign up or sign in to vote.
Using PHPBB3 CAPTCHA
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)

Share

About the Author

Mohammad Dayyan

Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

Comments and Discussions

 
GeneralVery good article Pinmemberparmando17-Feb-09 22:33 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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