Пример #1
0
<?php

session_start();
date_default_timezone_set('UTC');
$width = !empty($_GET['width']) && $_GET['width'] <= 1000 && $_GET['width'] > 0 ? $_GET['width'] : 300;
$height = !empty($_GET['height']) && $_GET['height'] <= 1000 && $_GET['height'] > 0 ? $_GET['height'] : 80;
$captcha = new SimpleCaptcha($width, $height);
$captcha->output();
class SimpleCaptcha
{
    private $image;
    private $width;
    private $height;
    private $chars_count = 5;
    private $chars_set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ12345689';
    private $colors = array('880000', '008800', '000088', '888800', '880088', '008888', '000000');
    private $lines_count = 8;
    private $bg_color = 'ffffff';
    private $session_key = 'simple_captcha';
    public function __construct($width, $height)
    {
        $this->width = intval($width);
        $this->height = intval($height);
    }
    public function output()
    {
        $this->initImage();
        $this->drawPoints();
        $this->drawLines();
        $text = $this->drawText();
        $this->setSession($text);