ACC SHELL
<?php
// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is mostly my work (based on a tutorial). Do not copy.
class Captcha
{
public static function template($id = null)
{
$var = 'captcha';
$id = U::request('id');
if ($id)
$var .= '-' . $id;
$font = page()->get('captcha-font', 'fast_money');
$font = U::fef('web/_fonts/'.$font.'/'.$font.'.ttf');
$width = 200; $height = 150;
$size = page()->get('captcha-font-size', 40);
$code = $_SESSION[$var] = U::randomString(6);
$angle = mt_rand(0, 20) - 10;
$bounding_box = imagettfbbox($size, $angle, $font, $code);
$width_text = $bounding_box[4] - $bounding_box[0]; $height_text = $bounding_box[5] - $bounding_box[1];
$x = (int) (($width - $width_text) / 2) + mt_rand(0, $width / 40);
$y = (int) (($height - $height_text) / 2) + mt_rand(0, $height / 10);
$image = imagecreate($width, $height);
//$color_background_red = mt_rand(0, 255); $color_background_green = mt_rand(0, 255); $color_background_blue = mt_rand(0, 255);
$color_background_red = 255; $color_background_green = 255; $color_background_blue = 255;
$color_background = imagecolorallocate($image, $color_background_red, $color_background_green, $color_background_blue);
$color_text = imagecolorallocate($image, 255 - $color_background_red, 255 - $color_background_green, 255 - $color_background_blue);
imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $color_background);
imagettftext($image, $size, $angle, $x, $y, $color_text, $font, $code);
header('Content-Type: image/jpeg');
echo imagejpeg($image);
imagedestroy($image);
}
public static function check($value, $id = null)
{
$var = 'captcha';
if ($id === null)
$id = U::request('id');
if ($id)
$var .= '-' . $id;
$original = @$_SESSION[$var];
if (!$original)
return false;
$from = 'oi';
$to = '01';
$original = strtr(strtolower($original), $from, $to);
$value = strtr(strtolower($value), $from, $to);
return ($original == $value);
}
}
?>
ACC SHELL 2018