Смена каптчи
Материал из Umicms
На одном из проектов потребовалось поменять стандартную captcha на что-нибудь более зловещее))) Для замены была выбрана KCAPTCHA (http://captcha.ru/kcaptcha/)
Скачиваем архив и распаковываем его в корень сайта (/kcaptcha/*.*)
В файле /kcaptcha/kcaptcha_config.php устанавливаем необходимые параметры.
Далее мы немного модифицируем сам класс каптчи /kcaptcha/kcaptcha.php Добавим две приватные переменные:
private $img_captch; private $jpeg_quality;
Уберём вывод каптчи из основного метода
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
if(function_exists("imagejpeg")){
header("Content-Type: image/jpeg");
imagejpeg($img2, null, $jpeg_quality);
}else if(function_exists("imagegif")){
header("Content-Type: image/gif");
imagegif($img2);
}else if(function_exists("imagepng")){
header("Content-Type: image/x-png");
imagepng($img2);
}
и заменим на
$this->img_captch = $img2; $this->jpeg_quality = $jpeg_quality;
Пишем метод для вывода каптчи
public function getImageCaptcha()
{
if(function_exists("imagejpeg")){
header("Content-Type: image/jpeg");
imagejpeg($this->img_captch, null, $this->jpeg_quality);
}else if(function_exists("imagegif")){
header("Content-Type: image/gif");
imagegif($this->img_captch);
}else if(function_exists("imagepng")){
header("Content-Type: image/x-png");
imagepng($this->img_captch);
}
}
Теперь займёмся собственно "прикручиванием" новой каптчи. Для этого заменим содржимое файла /captcha.php на приведённый код:
<?php
include './kcaptcha/kcaptcha.php';
if(file_exists('./sessions_memcached.php')) {
include './sessions_memcached.php';
}
session_start();
$captcha = new KCAPTCHA();
$code = $captcha->getKeyString();
$_SESSION['umi_captcha'] = md5($code);
$_SESSION['umi_captcha_plain'] = $code;
setcookie("umi_captcha", md5($code));
$captcha->getImageCaptcha();
?>
