font = dirname(__FILE__) . '/c.ttf'; $this->code = $this->generateCode($characters); /* insert the code into a cookie */ /* one-way encrypt the code, using the first two characters from the code */ $dstat = stat(dirname(__FILE__)); setcookie("_c", crypt(crypt("$this->code", substr("$this->code", 0, 2)), "" . $dstat['mtime']), 0, "/"); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 0, 0, 0); $noise_color = imagecolorallocate($image, 100, 120, 180); /* 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, $this->code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $this->code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past imagejpeg($image); imagedestroy($image); } } $captcha = new CaptchaSecurityImages(120, 40, 6); ?>