/var/www/hkosl.com/staraward/captcha.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class captcha
{
    protected 
$width 160;
    protected 
$height 45;

    private 
$pool '23456789abdefghijnqrtuyABDEFGHJLNQRTY';

    private 
$fonts = array();

    public function 
__construct($width null$height null)
    {
        if (!empty(
$width)) {
            
$this->width $width;
        }
        if (!empty(
$height)) {
            
$this->height $height;
        }
    }

    public function 
create_captcha()
    {
        
$image = @imagecreatetruecolor($this->width$this->height) or die("Cannot Initialize new GD image stream");

        
// set background to white and allocate drawing colours
        
$background imagecolorallocate($image0x000x000x8B);
        
imagefill($image00$background);
        
$linecolor imagecolorallocate($image0x1F0x3F0x70);
        
$textcolors = array(
            
$textcolor imagecolorallocate($image0xB40x950x3C),
            
$textcolor imagecolorallocate($image0xE80x210x25),
        );

        for (
$i 0$i 6$i++) {
            
imagesetthickness($imagerand(13));
            
imageline($image0rand(0$this->height), $this->widthrand(0$this->height), $linecolor);
        }

        
$fonts = array(
            
dirname(__FILE__) . DIRECTORY_SEPARATOR "fonts" DIRECTORY_SEPARATOR 'dejavu/1.ttf',
            
dirname(__FILE__) . DIRECTORY_SEPARATOR "fonts" DIRECTORY_SEPARATOR 'dejavu/2.ttf',
            
dirname(__FILE__) . DIRECTORY_SEPARATOR "fonts" DIRECTORY_SEPARATOR 'dejavu/3.ttf',
            
dirname(__FILE__) . DIRECTORY_SEPARATOR "fonts" DIRECTORY_SEPARATOR 'dejavu/4.ttf',
            
dirname(__FILE__) . DIRECTORY_SEPARATOR "fonts" DIRECTORY_SEPARATOR 'dejavu/5.ttf',
        );

        
$captcha '';
        for (
$x round($this->width 16); $x <= round($this->width 13 16); $x += round($this->width 5.5)) {
            
$captcha .= ($char $this->pool[rand(0strlen($this->pool) - )]);
            
imagettftext($imagerand(round($this->width 8.2), round($this->width 7.6)), rand(-3030), $xrand(round($this->height 2.25), round($this->height 1.1)), $textcolors[array_rand($textcolors)], $fonts[array_rand($fonts)], $char);
        }

        if (!
session_id()) {
            
session_start();
        }
        
$_SESSION['captcha'] = $captcha;

        
header('Content-type: image/png');
        
imagepng($image);
        
imagedestroy($image);
    }
}
$captcha = new captcha();
$captcha->create_captcha();