Hola, este simple formulario lo realicé ya hace un tiempo y lo suelo utilizar para hacer pruebas por lo que si puede servir de ayuda a alguién habrá cumplido su función.
############## FORMULARIO.PHP##############################
##################CHAPTA.PHP######################
if(isset($_SESSION["code"])){unset($_SESSION["code"]);};
session_start();
$code=rand(1000,9999);
$_SESSION["code"]=$code;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 86, 165); //background color blue
$fg = imagecolorallocate($im, 255, 255, 255);//text color white
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 5, 5, $code, $fg);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
";
echo "".REGISTRO_OK_EMPLEO."
";
echo "".REGISTRO_H_EMPLEO."
";
echo "".REGISTRO_TEXTO_OK."
";
echo "