28 lines
586 B
PHP
28 lines
586 B
PHP
<?php
|
|
session_start();
|
|
|
|
// Generar código aleatorio
|
|
$codigo = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 5);
|
|
$_SESSION['captcha'] = $codigo;
|
|
|
|
// Crear imagen
|
|
$imagen = imagecreatetruecolor(120, 40);
|
|
|
|
// Colores
|
|
$fondo = imagecolorallocate($imagen, 255, 255, 255);
|
|
$texto = imagecolorallocate($imagen, 0, 0, 0);
|
|
|
|
// Fondo blanco
|
|
imagefilledrectangle($imagen, 0, 0, 120, 40, $fondo);
|
|
|
|
// Escribir texto
|
|
imagestring($imagen, 5, 30, 10, $codigo, $texto);
|
|
|
|
// Tipo de imagen
|
|
header("Content-type: image/png");
|
|
|
|
// Mostrar imagen
|
|
imagepng($imagen);
|
|
imagedestroy($imagen);
|
|
?>
|