$width = 136;
$height = 25;
$im = imagecreate($width, $height);
$bg = imagecolorallocate($im, 235, 235, 235);
$len = 5;
$chars = '123456789';
$string = '';
for ($i = 0; $i < $len; $i++) {
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos};
}
$keycode = md5($string);
$_SESSION['GuvenlikKodu'] = md5($string);
setcookie('GuvenlikKodu',"$keycode",time()+3600);
$grid_color = imagecolorallocate($im, 185, 185, 185);
$number_to_loop = ceil($width / 7);
for($i = 0; $i < $number_to_loop; $i++) {
$x = ($i + 1) * 7;
imageline($im, $x, 0, $x, $height, $grid_color);
}
$number_to_loop = ceil($height / 5);
for($i = 0; $i < $number_to_loop; $i++) {
$y = ($i + 1) * 10;
imageline($im, 0, $y, $width, $y, $grid_color);
}
$text_color = imagecolorallocate($im, 32, 21, 75);
$rand_x = rand(0, $width - 50);
$rand_y = rand(0, $height - 15);
imagestring($im, 10, $rand_x, $rand_y, $string, $text_color);
header ("Content-type: image/png");
imagepng($im);
?>
Örnek;