<?php
function generateKey($len=7) {
    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0; $key = '' ;
	
    while ($i <= $len) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $key = $key.$tmp;
        $i++;
    }
    return $key;
}
session_start();
header ('Content-Type: image/png');
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
$tmp = substr($chars, $num, 1);
$randomNo = generateKey(4); 
$_SESSION['random_no'] = strtoupper($randomNo);
$image = @imagecreatetruecolor(110, 50) or die('Cannot Initialize new GD image stream');
$textColor = imagecolorallocate($image, 255, 255, 255);
$textFont = 'fonts/Alanden_.ttf';
imagettftext($image,20, 5, 10, 35, $textColor, $textFont, $_SESSION['random_no']);
imagepng($image);
imagedestroy($image);

?>