File: /home/ednermusika/ednergranados.com/captcha/captcha.php
<?php
session_start();
//FUNCION QUE GENERA UN TEXTO ALEATORIO
function randomText($length, $type=0) {
switch ($type)
{
case 0: $pattern = "1234567890ABCDEFGHKLMNPRSTUVWYZ"; break;
case 1: $pattern = "ABCDEFGHKLMNPRSTUVWYZ"; break;
case 2: $pattern = "1234567890"; break;
}
$max = strlen($pattern)-1;
for($i=0;$i < $length;$i++)
$key .= $pattern{mt_rand(0,$max)
};
return $key;
}
$texto = randomText(5);
$_SESSION['tmptxt'] = $texto;
$fuente = 'elephant.ttf';
$captcha = imagecreatefrompng("bgcaptcha.png");
$colText = imagecolorallocate ($captcha, 0x98, 0x4A, 0xFA);
imagettftext ($captcha, 14, 0, 7, 22, $colText, $fuente, $texto);
header ("Content-type: image/png");
imagepng ($captcha);
?>