Project

General

Profile

1
<?php
2

    
3
// $Id: captcha.php 2 2017-07-02 15:14:29Z Manuela $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
/*
27

    
28
Captcha generator
29

    
30
This file generates a captcha image.
31
Credits to http://php.webmaster-kit.com/ for the original code.
32

    
33
*/
34

    
35
require_once("../config.php");
36

    
37
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg') AND isset($_SESSION['captcha'])) {
38
    
39
    $image = imagecreate(120, 30);
40
    
41
    $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
42
    $gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
43
    $darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50);
44
    
45
    srand((double)microtime()*1000000);
46
    
47
    for($i = 0; $i < 30; $i++) {
48
        $x1 = rand(0,120);
49
        $y1 = rand(0,30);
50
        $x2 = rand(0,120);
51
        $y2 = rand(0,30);
52
        imageline($image, $x1, $y1, $x2, $y2 , $gray);  
53
    }
54
    
55
    $x = 0;
56
    for($i = 0; $i < 5; $i++) {
57
        $fnt = rand(3,5);
58
        $x = $x + rand(12 , 20);
59
        $y = rand(7 , 12); 
60
        imagestring($image, $fnt, $x, $y, substr($_SESSION['captcha'], $i, 1), $darkgray); 
61
    }
62
    
63
    // start buffering for size determination
64
    ob_start();
65
    // add no cache headers
66
    header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
67
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
68
    header("Cache-Control: no-store, no-cache, must-revalidate");
69
    header("Cache-Control: post-check=0, pre-check=0", false);
70
    header("Pragma: no-cache");
71
    header("Content-type: image/png");
72
    // Make image
73
    imagepng($image);
74
    // Fetch length
75
    header("Content-Length: " . ob_get_length());
76
    // send image and turn off buffering
77
    ob_end_flush();
78
    // clear memory
79
    imagedestroy($image);
80

    
81
}
82

    
83
?>
    (1-1/1)