在本文中,将探讨如何在项目中集成并使用PHPBB3的验证码功能。首先,要感谢Xore(Robert Hetzler)的贡献,他为此付出了巨大的努力。可以使用GNU公共许可证在项目中使用这个类。
首先,编写了一个用于生成随机表达式的PHP类(DayyanRandomCharacters)。下面是一个示例:
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 />';
使用了captcha_gd.php文件,可以在phpBB3\includes\captcha文件夹中找到它。这个文件中有三个类:
captcha类有一个名为execute的函数,必须使用它。execute函数的签名如下:
function execute($code, $seed)
在这个函数的末尾,可以看到这些表达式:
header('Content-Type: image/png');
header('Cache-control: no-cache, no-store');
禁用了它们,因为想改变显示验证码图像的方式。如果想通过execute函数直接显示验证码图像,必须启用它们。
在captcha类中有两个变量,可以改变图像的大小:
var $width = 360;
var $height = 96;
在PHPBB3验证码中有一个全局数组($config),用于更改配置。示例如下:
//Configurations of PHPBB3 captcha
$config = array('captcha_gd_x_grid' => false,
'captcha_gd_y_grid' => false,
'captcha_gd_foreground_noise' => false);
$config = array('captcha_gd_x_grid' => false,
'captcha_gd_y_grid' => false,
'captcha_gd_foreground_noise' => true);
结果如下:
$config = array('captcha_gd_x_grid' => false,
'captcha_gd_y_grid' => true,
'captcha_gd_foreground_noise' => false);
结果如下:
$config = array('captcha_gd_x_grid' => true,
'captcha_gd_y_grid' => false,
'captcha_gd_foreground_noise' => false);
<?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 ?>" />