Просмотр файла captcha.php

Размер файла: 2.29Kb
<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/MultiWave.php';
$show_all=true; // показ для всех, в противном случае невозможно будет пройти регистрацию
include_once 'sys/inc/user.php';

class captcha
{
var $str;
var $x = 100;
var $y = 40;
var $img;
var $gif=false;
var $png=false;
var $jpg=false;

function captcha($str)
{
if (!function_exists('gd_info')){header('Location: /style/errors/gd_err.gif');exit;}
if (imagetypes() & IMG_PNG)$this->png=true;
if (imagetypes() & IMG_GIF)$this->gif=true;
if (imagetypes() & IMG_JPG)$this->jpg=true;
$this->str=$str;

$this->img=imagecreatetruecolor($this->x, $this->y);
imagefill($this->img, 0, 0, imagecolorallocate ($this->img, 255, 255, 255));
}

function create()
{
for ($i=0;$i<5 ;$i++ ) {
$n=$this->str{$i};
if ($this->png)$num[$n]=imagecreatefrompng(H.'/style/captcha/'.$n.'.png');
elseif ($this->gif)$num[$n]=imagecreatefromgif(H.'/style/captcha/'.$n.'.gif');
elseif ($this->jpg)$num[$n]=imagecreatefromjpeg(H.'/style/captcha/'.$n.'.jpg');
imagecopy($this->img, $num[$n], $i*15+10, 8, 0, 0, 15, 20);
}
}
function MultiWave()
{
include_once H.'sys/inc/MultiWave.php';
$this->img=MultiWave($this->img);
}

function colorize($value=90)
{
if (function_exists('imagefilter'))
imagefilter($this->img, IMG_FILTER_COLORIZE, mt_rand(0, $value), mt_rand(0, $value), mt_rand(0, $value));
}

function output($q=50)
{
@ob_end_clean();
if ($this->jpg)
{
header("Content-type: image/jpeg");
imagejpeg($this->img,null,$q);
}
elseif ($this->png)
{
header("Content-type: image/png");
imagepng($this->img);
}
elseif ($this->gif)
{
header("Content-type: image/gif");
imagegif($this->img);
}
exit;
}



}

$_SESSION['captcha']='';
// генерируем код
for ($i=0;$i<5;$i++) {$_SESSION['captcha'].=mt_rand(0, 9);}

$captcha = new captcha($_SESSION['captcha']);


$captcha->create(); //создание изображения

$captcha->MultiWave(); // искажение изображения

$captcha->colorize(); // придаем цвет, если возможно

$captcha->output(); // вывод изображения
?>
?>