<?php
session_start();
$liste = '0123456789';
$code = '';
while(strlen($code) != 6) {
   $code .= $liste[rand(0,strlen($liste)-1)];
}

$_SESSION['code']=$code;
#$img = imageCreate(100, 30) or die ("Problème de création GD");
$img = imagecreatetruecolor(100, 30) or die("Problem with GD creation");
$background_color = imagecolorallocate ($img, 255, 255, 255);
$ecriture_color = imagecolorallocate ($img, 0, 0, 0);
$code_police=5;
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header("Content-type: image/gif");

$font = $_SERVER['DOCUMENT_ROOT'].'/_ttf/PURIBI10.TTF';
$black[0] = imagecolorallocate($img, 224, 221, 214);
$black[1] = imagecolorallocate($img, 139, 129, 105);
//$black[1] = imagecolorallocate($img, 0, 0, 0);
$b = 5;
for($i=0;$i!=6;$i++){
	($i%2 == 0) ? $j = 0 : $j = 1;
	$y = rand(15,25);
	imagettftext($img, 16, 0, $b+2, $y+1, $black[1], $font, $code[$i]);
	imagettftext($img, 16, 0, $b, $y, $black[0], $font, $code[$i]);
	$b+=16;
}
imagegif($img);
imagedestroy($img);
/*
imageline  ($img,0,5,100,5,$black[1]);
imageline  ($img,0,10,100,10,$black[1]);
imageline  ($img,0,15,100,15,$black[1]);
imageline  ($img,0,20,100,20,$black[1]);
imageline  ($img,0,25,100,25,$black[1]);
*/

/*
if(function_exists('imagegif'))
	imagegif($img,'',80);
} else {
	imageDestroy($img);
	die('No image support in this PHP server');
}
if ($img) {
	imageDestroy($img);
}
*/
/*
// Create a new image instance


// Make the background white
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);

// Draw a text string on the image
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);

// Output the image to browser
header('Content-Type: image/gif');

*/

?>