1
|
<?php
|
2
|
|
3
|
// $Id: calc_image.php 615 2008-01-27 14:29:23Z thorn $
|
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
|
if(!isset($_SESSION['captcha_time']))
|
30
|
exit;
|
31
|
unset($_SESSION['captcha_time']);
|
32
|
|
33
|
// Captcha
|
34
|
$_SESSION['captcha'] = '';
|
35
|
mt_srand((double)microtime()*1000000);
|
36
|
$n = mt_rand(1,3);
|
37
|
switch ($n) {
|
38
|
case 1:
|
39
|
$x = mt_rand(1,9);
|
40
|
$y = mt_rand(1,9);
|
41
|
$_SESSION['captcha'] = $x + $y;
|
42
|
$cap = "$x+$y";
|
43
|
break;
|
44
|
case 2:
|
45
|
$x = mt_rand(10,20);
|
46
|
$y = mt_rand(1,9);
|
47
|
$_SESSION['captcha'] = $x - $y;
|
48
|
$cap = "$x-$y";
|
49
|
break;
|
50
|
case 3:
|
51
|
$x = mt_rand(2,10);
|
52
|
$y = mt_rand(2,5);
|
53
|
$_SESSION['captcha'] = $x * $y;
|
54
|
$cap = "$x*$y";
|
55
|
break;
|
56
|
}
|
57
|
|
58
|
$image = imagecreate(100, 30);
|
59
|
|
60
|
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
|
61
|
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
|
62
|
$darkgray = imagecolorallocate($image, 0x30, 0x30, 0x30);
|
63
|
|
64
|
srand((double)microtime()*1000000);
|
65
|
|
66
|
for($i = 0; $i < 30; $i++) {
|
67
|
$x1 = rand(0,100);
|
68
|
$y1 = rand(0,30);
|
69
|
$x2 = rand(0,100);
|
70
|
$y2 = rand(0,30);
|
71
|
imageline($image, $x1, $y1, $x2, $y2 , $gray);
|
72
|
}
|
73
|
|
74
|
$x = 0;
|
75
|
$l = strlen($cap);
|
76
|
for($i = 0; $i < $l; $i++) {
|
77
|
$fnt = rand(3,5);
|
78
|
$x = $x + rand(12 , 20);
|
79
|
$y = rand(7 , 12);
|
80
|
imagestring($image, $fnt, $x, $y, substr($cap, $i, 1), $darkgray);
|
81
|
}
|
82
|
|
83
|
captcha_header();
|
84
|
imagepng($image);
|
85
|
imagedestroy($image);
|
86
|
|
87
|
?>
|