Вход Регистрация
Файл: system/helpers/captcha.php
Строк: 30
<?php

function captcha()
{
    
$fontFile = THEME . 'fonts/captcha.otf';
    
$fontSize = 24;
    
$height = 50;
    
$width = 160;

    do 
    {
        
$code = substr(str_shuffle(str_repeat('1234567890', 3)), 0, mt_rand(3, 5));
    } 
    while (
preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|ww/', $code));

    
$image = imagecreatetruecolor($width, $height);

    
imagesavealpha($image, true);
    
imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));

    
$text = str_split($code);
    
$len = count($text);

    for (
$i = 0; $i < $len; $i++) 
    {
        
$angle = mt_rand(-10, 10);
        
$x = ($width - $fontSize) / $len * $i + ($fontSize / 2);
        
$x = mt_rand($x, $x + 5);
        
$y = $height - (($height - $fontSize) / 2);
        
$color = imagecolorallocatealpha($image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100), mt_rand(20, 40));

         
imagettftext($image, $fontSize, $angle, $x, $y, $color, $fontFile, $text[$i]);
    }

    
$_SESSION['captcha'] = $code;

    
ob_start();

    
imagepng($image);
    
imagedestroy($image);

    return 
'data:image/png;base64,' . base64_encode(ob_get_clean());
}
Онлайн: 2
Реклама