1
|
<?php
|
2
|
|
3
|
// $Id$
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, 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
|
require_once("../../../config.php");
|
27
|
require_once(WB_PATH.'/include/captcha/captcha.php');
|
28
|
|
29
|
// get lists of fonts and backgrounds
|
30
|
require_once(WB_PATH.'/search/search_modext.php');
|
31
|
list($fonts, $dirs) = list_files_dirs(WB_PATH.'/include/captcha/fonts', false);
|
32
|
list($bgs, $dirs) = list_files_dirs(WB_PATH.'/include/captcha/backgrounds', false);
|
33
|
$fonts = clear_filelist($fonts, '\.ttf$');
|
34
|
$bgs = clear_filelist($bgs, '\.png$');
|
35
|
|
36
|
// make random string
|
37
|
if(!function_exists('randomString')) {
|
38
|
function randomString($len) {
|
39
|
list($usec, $sec) = explode(' ', microtime());
|
40
|
srand((float)$sec + ((float)$usec * 100000));
|
41
|
//$possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghkmnpqrstuvwxyz23456789";
|
42
|
$possible="abdfhkrsvwxyz23456789";
|
43
|
$str="";
|
44
|
while(strlen($str)<$len) {
|
45
|
$str.=substr($possible,(rand()%(strlen($possible))),1);
|
46
|
}
|
47
|
return($str);
|
48
|
}
|
49
|
}
|
50
|
$text = randomString(5); // number of characters
|
51
|
$_SESSION['captcha'] = $text;
|
52
|
|
53
|
// choose a font and background
|
54
|
$font = $fonts[array_rand($fonts)];
|
55
|
$bg = $bgs[array_rand($bgs)];
|
56
|
// get image-dimensions
|
57
|
list($width, $height, $type, $attr) = getimagesize($bg);
|
58
|
|
59
|
// create image
|
60
|
$image_failed = true;
|
61
|
do {
|
62
|
$image = ImageCreateFromPNG($bg); // backgroundimage
|
63
|
$grey = rand(0,50);
|
64
|
$color = ImageColorAllocate($image, $grey, $grey, $grey); // Farbe
|
65
|
$ttf = $font;
|
66
|
$ttfsize = 25; // fontsize
|
67
|
$angle = rand(0,5);
|
68
|
$t_x = rand(5,30);
|
69
|
$t_y = rand($height-10,$height-2);
|
70
|
$res = imagettftext($image, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
|
71
|
// check if text fits into the image
|
72
|
if(($res[0]>0 && $res[0]<$width) && ($res[1]>0 && $res[1]<$height) &&
|
73
|
($res[2]>0 && $res[2]<$width) && ($res[3]>0 && $res[3]<$height) &&
|
74
|
($res[4]>0 && $res[4]<$width) && ($res[5]>0 && $res[5]<$height) &&
|
75
|
($res[6]>0 && $res[6]<$width) && ($res[7]>0 && $res[7]<$height)
|
76
|
) {
|
77
|
$image_failed = false;
|
78
|
}
|
79
|
} while($image_failed);
|
80
|
|
81
|
captcha_header();
|
82
|
ob_start();
|
83
|
imagepng($image);
|
84
|
header("Content-Length: ".ob_get_length());
|
85
|
ob_end_flush();
|
86
|
imagedestroy($image);
|
87
|
|
88
|
?>
|