okram: como siempre........ excelente!!!! tenes que escribir un libro de PHP.... yo lo compraría (aunque aceptaria una copia gratis tb)
Código PHP:
<?php
Function pass_gen($len=8){
$string = '';
$ok = false;
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for ($i = 0; $i < $len; $i++){
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos};
}
return ($string);
}
Function captcha($imagen_file){
//header("Content-type: image/png");
//$imagen_file = "captcha.png";
$im = @imagecreate(100, 50) or die("Cannot Initialize new GD image stream");
$clave = pass_gen();
imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 5, 15, 15, $clave, $text_color);
imagepng($im,$imagen_file);
imagedestroy($im);
return ($clave);
}
$c = captcha("captcha.png");
echo $c.'<p/>';
echo '<img src="captcha.png"/>';
?>