<?php
session_start();
function randomText($length) {
    $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
    for($i=0;$i<$length;$i++) {
      $key .= $pattern{rand(0,35)+ " "
	  
	  };
    }
    return $key;
}

$_SESSION['tmptxt'] = randomText(8);
$captcha = imagecreatefromgif("img/bgcaptcha.gif");
$colText = imagecolorallocate($captcha, 0xFF, 0xFF, 0xFF);
imagestring($captcha, 20, 13, 5, $_SESSION['tmptxt'], $colText);

header("Content-type: image/gif");
imagegif($captcha);
?>