Auf englisch ...

Use this code below to replace phpbb's default (weak) captcha.
This one is based on a tutorial from php-kurse.com.
Install
====
1. Create a folder named captcha/ in phpBB's main folder.
2. place some .ttf files (Fonts) there, can copy from Windows\fonts
3. Place 2 png's of 250px x 250px named
3a. captcha-counterclock.png
3b. captcha-clock.png
inside the folder
4. copy this code and replace includes/usercp_confirm.php
Code: Alles auswählen
<?php
/***************************************************************************
* usercp_confirm.php
* -------------------
* begin : Saturday, Jan 15, 2003
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: usercp_confirm.php,v 1.1.2.4 2006/05/30 19:29:43 grahamje Exp $
* Modified by Ueli Kistler 2007, captcha clock
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
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;
}
$file[0] = "captcha/captcha-clock.png";
$file[1] = "captcha/captcha-counterclock.png";
$confirm_id = htmlspecialchars($HTTP_GET_VARS['id']);
// Define available charset
$chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');
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;
}
/**
Init
**/
$phpbb_root_path = str_replace('index.'.$phpEx, '', realpath($phpbb_root_path.'index.'.$phpEx));
$fonts = array();
if ($fonts_dir = opendir($phpbb_root_path.'captcha/'))
{
while (true == ($fontfile = @readdir($fonts_dir)))
{
if ((substr(strtolower($fontfile), -3) == 'ttf'))
{
$fonts[] = $fontfile;
}
}
closedir($fonts_dir);
}
// Randomizer
list($usec, $sec) = explode(' ', microtime());
mt_srand($sec * $usec);
// Output image
header('Content-Type: image/png');
header('Cache-control: no-cache, no-store');
$codeorg = $code;
// randomize clock/counterclock
if (getDirection() == 0)
{
$image = ImageCreateFromPNG ($file[0]);
}
else {
$image = ImageCreateFromPNG ($file[1]);
$code = strrev($code);
}
ImageTTFText ($image, getSize(), getRotation(), 140, 70, getColour($image), $phpbb_root_path.getFont($fonts), $code[0]);
ImageTTFText ($image, getSize(), getRotation(), 180, 130, getColour($image), $phpbb_root_path.getFont($fonts), $code[1]);
ImageTTFText ($image, getSize(), getRotation(), 130, 210, getColour($image), $phpbb_root_path.getFont($fonts), $code[2]);
ImageTTFText ($image, getSize(), getRotation(), 80, 190, getColour($image), $phpbb_root_path.getFont($fonts), $code[3]);
ImageTTFText ($image, getSize(), getRotation(), 80, 120, getColour($image), $phpbb_root_path.getFont($fonts), $code[4]);
ImageTTFText ($image, getSize(), getRotation(), 90, 50, getColour($image), $phpbb_root_path.getFont($fonts), $code[5]);
ImageTTFText ($image, 12, 0, 0, 240, getColour($image), $phpbb_root_path.getFont($fonts), $codeorg);
// Ausgabe im Format PNG
ImagePng ($image);
// Resourcen wieder freigeben
ImageDestroy ($image);
unset($image);
exit;
function getDirection()
{
return mt_rand(0,1);
}
function getColour($image)
{
return ImageColorAllocate ($image, mt_rand(0, 255),mt_rand(0, 255),mt_rand(0, 255));
}
function getRotation()
{
return mt_rand(-90,90);
}
function getSize()
{
return mt_rand(20,32);
}
function getFont($fonts)
{
return '/captcha/'.$fonts[rand(0, (count($fonts)-1))];
}
?>