Писалось для phpBB 2.0.18, проверялось на hostland'е. Цветность, прозрачность букв, путь к каталогу со шрифтами настраивается в скрипте.
includes/usercp_confirm.php
Код: Выделить всё
<?php
if ( !defined('IN_PHPBB') )
{
die('Hacking attempt');
exit;
}
// Note to potential users of this code ...
//
// Remember this is released under the _GPL_ and is subject
// to that licence. Do not incorporate this within software
// released or distributed in any way under a licence other
// than the GPL. We will be watching ... ;)
// Do we have an id? No, then just exit
if (empty($HTTP_GET_VARS['id']))
{
exit;
}
$confirm_id = htmlspecialchars($HTTP_GET_VARS['id']);
if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
{
$confirm_id = '';
}
// Try and grab code for this id and session
$sql = 'SELECT code
FROM ' . CONFIRM_TABLE . "
WHERE session_id = '" . $userdata['session_id'] . "'
AND confirm_id = '$confirm_id'";
$result = $db->sql_query($sql);
// If we have a row then grab data else create a new id
if ($row = $db->sql_fetchrow($result))
{
$db->sql_freeresult($result);
$code = $row['code'];
}
else
{
exit;
}
/*
* The code below was written by Keeper
*/
// Define TTF fonts directory
$ttf_dir = '/home/host1359/ttf/';
// Define an available charset
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789';
// Get a random element from given array
function rand_elem( $list) {
$max = is_array($list) ? count($list) : strlen($list);
return $list[ mt_rand( 0, $max-1) ];
}
// Generate a random color
function rand_color( $img, $fg = true) {
$ind = mt_rand(0,2);
$rgb = array();
for ($i=0; $i<=2; $i++) {
if ($fg) {
// Foreground color (for characters)
$rgb[$i] = ($i == $ind) ? mt_rand( 64, 128) : mt_rand( 0, 64);
} else {
// Background color
$rgb[$i] = ($i == $ind) ? mt_rand( 128, 255) : mt_rand( 96, 255);
}
}
return ($fg ? imagecolorallocatealpha( $img, $rgb[0], $rgb[1], $rgb[2], 60)
: imagecolorallocate( $img, $rgb[0], $rgb[1], $rgb[2]) );
}
// Generate a random string
list($usec, $sec) = explode( ' ', microtime());
mt_srand( $sec * $usec);
/*
$code = '';
for ($i = 0; $i < 6; $i++) {
$code .= rand_elem($chars);
}
*/
$codelen = strlen( $code);
// Create image surface
$total_width = 320;
$total_height = 50;
$img = imagecreatetruecolor( $total_width, $total_height);
$bgcolor = imagecolorallocate( $img, 240, 240, 240);
imagefill( $img, 0, 0, $bgcolor);
// Randomly fill image with spots
for ($i = 0; $i < 5000; $i++) {
$x = mt_rand( 0, $total_width);
$y = mt_rand( 0, $total_height);
$r = mt_rand( 2, 6);
$color = rand_color( $img, false);
imagefilledellipse( $img, $x, $y, $r, $r, $color);
}
// Write a text, char by char
$ttf_list = glob( $ttf_dir.'*.ttf');
$char_width = 30;
$left_margin = mt_rand( 10, $total_width - $codelen * $char_width - 10);
for ($i = 0; $i < $codelen; $i++) {
$size = mt_rand( 24, 30);
$angle = mt_rand( -10, 10);
$x = $i * $char_width + $left_margin;
$y = mt_rand( 35, $total_height-10);
$color = rand_color( $img);
$ttf = rand_elem( $ttf_list);
imagettftext( $img, $size, $angle, $x, $y, $color, $ttf, $code[$i]);
}
// Output image to browser
header( "Content-type: image/png");
header( "Cache-control: no-cache, no-store");
imagepng( $img);
imagedestroy( $img);
?>