Fichier
captcha.php
<?php
session_start();
$string = '';
for ($i = 0; $i < $max=2; $i++) {
$string .= mt_rand(0, 9);
$string .= chr(rand(97, 122));
if($i==$max-1)
$string .= mt_rand(0, 9);
}
$_SESSION['captcha'] = $string; //store the captcha
$dir = 'fonts/';
header("Content-type: image/png");
$image = @imagecreatetruecolor(200, 50) or die("Impossible de crée un flux d'image GD"); //custom image size
$font = "defused.ttf"; // custom font style
$color = imagecolorallocate($image, 86, 86, 86); // custom color
$bg = imagecolorallocate($image, 255, 255, 255); // custom background color
imagefilledrectangle($image,0,0,399,99, $bg);
imagettftext ($image, 30, 0, 10, 40, $color, $dir.$font, $_SESSION['captcha']);
imagepng($image);
imagedestroy($image);
?>