It was working great yesterday,.. and now. .. it isn't.. ???
<?php
session_start();
if(isset($_POST["captcha"])) {
if(($_SESSION['captcha_code'] == $_POST['captcha']) && (!empty($_SESSION['captcha_code'])) ) {
//Passed!
$captcha_msg="Thank you";
}else{
// Not passed 8-(
$captcha_msg="*** invalid image code, please put the right code in the box";
if(isset($_POST["MM_insert"])){
unset($_POST["MM_insert"]);
}
if(isset($_POST["MM_update"])){
unset($_POST["MM_update"]);
}
}
}
class CaptchaImage {
//var $font = realpath("verdana.ttf");
var $font = "/home55/www/website.com/this/verdana.ttf";
function hex_to_dec($hexcolor){
//convert hex hex values to decimal ones
$dec_color=array('r'=>hexdec(substr($hexcolor,0,2)),'g'=>hexdec(substr($hexcolor,2,2)),'b'=>hexdec(substr($hexcolor,4,2)));
return $dec_color;
}
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaImage($width='120',$height='30',$characters='6',$hex_bg_color='FFFFFF',$hex_text_color="000000",$hex_noise_color="CC0000", $img_file='captcha.jpg') {
$rgb_bg_color=$this->hex_to_dec($hex_bg_color);
$rgb_text_color=$this->hex_to_dec($hex_text_color);
$rgb_noise_color=$this->hex_to_dec($hex_noise_color);
$code = $this->generateCode($characters);
/* font size will be 60% of the image height */
$font_size = $height * 0.35;
$image = @imagecreate($width, $height) or die('Cannot Initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, $rgb_bg_color['r'], $rgb_bg_color['g'],$rgb_bg_color['b']);
$text_color = imagecolorallocate($image, $rgb_text_color['r'], $rgb_text_color['g'],$rgb_text_color['b']);
$noise_color = imagecolorallocate($image, $rgb_noise_color['r'], $rgb_noise_color['g'],$rgb_noise_color['b']);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code);
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code);
/* save the image */
imagejpeg($image,$img_file);
imagedestroy($image);
echo "<img src=\"$img_file?".time()."\" width=\"$width\" height=\"$height\" alt=\"security code\" id=\"captchaImg\">";
$_SESSION['captcha_code'] = $code;
}
}
?>
And then it is getting stuck down here: What I mean by stuck, is it is loading everything ahead of this.. but stops right before this php $captcha call???
<td valign="bottom"><?php $captcha = new CaptchaImage(120,50,6,'FFFFFF','000000','99CC00');?><label><input name="captcha" type="text" class="text_calendar2" id="captcha" size="12" /> </label>
<strong>← INSERT CODE HERE</strong><br />
<div style="color:#CC3333; font-weight:bold; margin-left:25px; background-color:#FFFF00; margin-bottom:7px; margin-top:7px"><?php echo $captcha_msg ?></div> </td>
Anybody see anything odd?? Like I said, this just all of a sudden happened. Like a ghost did it. It was working fine yesterday and then today.. bang... Thanks in advance.