Verification code error
Posted: Sun Mar 19, 2006 11:45 am
When I run this script:
I get this error:
Code: Select all
<?php
function gen_rand_img()
{
/**
* We define some static items here
*/
## Define our random sentences
$sentences = array(
'This is a random string',
'Lorum Ipsum Doler sit amet',
'The quick brown fox jumps over the lazy dog',
'Kick the tires and light the fires Big Daddy'
);
## Define font file
putenv('GDFONTPATH='.realpath('.')); // Set GD font path to this directory
$font = 'ProggyCleanSZBP'; // Leave extension off
## Define some random colors
## http://december.com/html/spec/colordec.html
$bg_colors = array( ## BACKGROUND COLORS
'176.196.222', // Blue
'204.153.204', // Purple
'204.204.204', // Gray
'227.81.82', // Red
'150.200.162' // Green
);
$font_colors = array( ## FONT COLORS
'0.0.139', // Blue
'104.34.139', // Purple
'79.79.79', // Gray
'128.0.0', // Red
'59.94.15' // Green
);
$img_width = 150; ## Image Width
$img_height = 75; ## Image height
$fnt_size = 24; ## Font-Size
$let_space = 10; ## Letter Spacing
$str_length = 6; ## Length of Random String
/**************/
## Define random string generation function:
function gen_random_string($length=5, $str='')
{
for($i=1; $i<=$length; $i++)
{
$ord = rand(48, 90);
if( ( ($ord>=48) && ($ord<=57) ) || ( ($ord>=65) && ($ord<=90) ) )
{
$str .= chr($ord);
}
else
{
$str .= gen_random_string(1);
}
}
return $str;
}
## Get the random string
$str_snt = rand(0,1); // 0: sentences, 1: random string
if($str_snt == 0)
{
$rnd_str = str_replace(' ', '', strtoupper($sentences[rand(0,count($sentences)-1)]));
$rnd_str = substr($rnd_str, rand(0,strlen($rnd_str)-$str_length), $str_length);
}
else
{
$rnd_str = gen_random_string($str_length);
}
/**
* Image functions
*/
## Create the image
$img = imagecreate($img_width, $img_height) or die('Can not initialize GD Image Library');
## Define Background & Text colors
list($br, $bg, $bb) = explode('.', $bg_colors[rand(0, count($bg_colors)-1)]);
list($tr, $tg, $tb) = explode('.', $font_colors[rand(0, count($font_colors)-1)]);
$bg_color = imagecolorallocate($img, $br, $bg, $bb);
$txt_color = imagecolorallocate($img, $tr, $tg, $tb);
$line_clr = imagecolorallocate($img, 0, 0, 0);
## Create box around image
imageline($img, 0, 0, $img_width, 0, $line_clr); # Top left to top right
imageline($img, 0, 0, 0, $img_height, $line_clr); # Top left to bottom left
imageline($img, 0, $img_height-1, $img_width, $img_height-1, $line_clr); # Bottom Left to Bottom right
imageline($img, $img_width-1, 0, $img_width-1, $img_height, $line_clr); # Top right to bottom Right
## Write string into image
for($i=0; $i<strlen($rnd_str); $i++)
{
imagettftext($img, $fnt_size, rand(-30, 30), (($i*$fnt_size)+$let_space), rand($fnt_size+5, ($img_height-$fnt_size-5)), $txt_color, $font, $rnd_str{$i});
}
imagegif($img, 'rand_image.gif');
return $rnd_str;
}
if(isset($_POST) && !empty($_POST))
{
if(md5(strtoupper($_POST['vcode'])) == $_POST['_vcode'])
{
echo '<h3 style="color: #090;">Verified!!</h3>';
}
else
{
echo '<h3 style="color: #f00;">Unverified!!</h3>';
}
}
$str = gen_rand_img();
?>Fatal error: Call to undefined function: imagettftext() in /home/visitsha/public_html/vcode.php on line 99