Project

General

Profile

« Previous | Next » 

Revision 1693

Added by Dietmar almost 12 years ago

  1. fixed deprecated erigi in captcha

View differences:

calc_ttf_image.php
27 27
require_once(WB_PATH.'/include/captcha/captcha.php');
28 28

  
29 29
if(!isset($_SESSION['captcha_time']))
30
	exit;
30
	exit('missing captcha_time');
31 31
//unset($_SESSION['captcha_time']);		// otherwise there can't be 2 captchas on one page!
32 32

  
33 33
// get lists of fonts and backgrounds
......
36 36
$t_bgs = file_list(WB_PATH.'/include/captcha/backgrounds');
37 37
$fonts = array();
38 38
$bgs = array();
39
foreach($t_fonts as $file) if(eregi('\.ttf$',$file)) $fonts[]=$file;
40
foreach($t_bgs as $file) if(eregi('\.png$',$file)) $bgs[]=$file;
39
foreach($t_fonts as $file) { if(preg_match('/\.ttf/',$file)) { $fonts[]=$file; } }
40
foreach($t_bgs as $file) { if(preg_match('/\.png/',$file)) { $bgs[]=$file; } }
41 41

  
42 42
// Captcha
43 43
$sec_id = '';
......
50 50
		$x = mt_rand(1,9);
51 51
		$y = mt_rand(1,9);
52 52
		$_SESSION['captcha'.$sec_id] = $x + $y;
53
		$cap = "$x+$y"; 
54
		break; 
53
		$cap = "$x+$y";
54
		break;
55 55
	case 2:
56 56
		$x = mt_rand(10,20);
57 57
		$y = mt_rand(1,9);
58
		$_SESSION['captcha'.$sec_id] = $x - $y; 
59
		$cap = "$x-$y"; 
58
		$_SESSION['captcha'.$sec_id] = $x - $y;
59
		$cap = "$x-$y";
60 60
		break;
61 61
	case 3:
62 62
		$x = mt_rand(2,10);
63 63
		$y = mt_rand(2,5);
64
		$_SESSION['captcha'.$sec_id] = $x * $y; 
65
		$cap = "$x*$y"; 
64
		$_SESSION['captcha'.$sec_id] = $x * $y;
65
		$cap = "$x*$y";
66 66
		break;
67 67
}
68 68
$text = $cap;
......
104 104
		if(++$count > 4) // too many tries! Use the image
105 105
			break;
106 106
	} while($image_failed);
107
	
107

  
108 108
} else {
109
	
109

  
110 110
	// draw whole string at once
111 111
	$image_failed = true;
112 112
	$count=0;
......
121 121
		$y = mt_rand($height-10,$height-2);
122 122
		$res = imagettftext($image, $ttfsize, $angle, $x, $y, $color, $ttf, $text);
123 123
		// check if text fits into the image
124
		if(($res[0]>0 && $res[0]<$width) && ($res[1]>0 && $res[1]<$height) && 
125
			 ($res[2]>0 && $res[2]<$width) && ($res[3]>0 && $res[3]<$height) && 
126
			 ($res[4]>0 && $res[4]<$width) && ($res[5]>0 && $res[5]<$height) && 
124
		if(($res[0]>0 && $res[0]<$width) && ($res[1]>0 && $res[1]<$height) &&
125
			 ($res[2]>0 && $res[2]<$width) && ($res[3]>0 && $res[3]<$height) &&
126
			 ($res[4]>0 && $res[4]<$width) && ($res[5]>0 && $res[5]<$height) &&
127 127
			 ($res[6]>0 && $res[6]<$width) && ($res[7]>0 && $res[7]<$height)
128 128
		) {
129 129
			$image_failed = false;
......
131 131
		if(++$count > 4) // too many tries! Use the image
132 132
			break;
133 133
	} while($image_failed);
134
	
134

  
135 135
}
136 136

  
137 137
imagealphablending($reload, TRUE);
......
145 145
captcha_header();
146 146
ob_start();
147 147
imagepng($image);
148
header("Content-Length: ".ob_get_length()); 
148
header("Content-Length: ".ob_get_length());
149 149
ob_end_flush();
150 150
imagedestroy($image);
151

  
152
?>

Also available in: Unified diff