Ho finalmente trovato Captca senza DB, non riesco però a visualizzare l'immagine con i caratteri penso sia questo da modificare, ho inserito la stringa di dove si trova il file arial.ttf
$font = "C:windows\fonts\arial.ttf";
Nel form:
<img src="captca-image.php" alt="CAPTCHA image" width="60" height="20" vspace="1" align="top" />
<input type="text" name="validator" id="validator" size="5" />
<font size="2" color="red" face="arial">Scrivi il codice</font>
<?php
if (!empty($_POST['validator']) && $_POST['validator'] == $_SESSION['rand_code']) {
unset($_SESSION['rand_code']);
}
?>
Ho creato un file captca-image.php
<?php
//Captca code
session_start();
if (empty($_SESSION['rand_code'])){
$str = "";
$length = 0;
for ($i = 0; $i < 4; $i++){
// this numbers refer to numbers of the ascii table (small-caps)
$str .= chr(rand(97, 122));
}
$_SESSION['rand_code'] = $str;
}
$imgX = 60;
$imgY = 20;
$image = imagecreatetruecolor(60, 20);
$backgr_col = imagecolorallocate($image, 238,239,239);
$border_col = imagecolorallocate($image, 208,208,208);
$text_col = imagecolorallocate($image, 46,60,31);
imagefilledrectangle($image, 0, 0, 60, 20, $backgr_col);
imagerectangle($image, 0, 0, 59, 19, $border_col);
$font = "C:windows\fonts\arial.ttf";
$font_size = 10;
$angle = 0;
$box = imagettfbbox($font_size, $angle, $font, $_SESSION['rand_code']);
$x = (int)($imgX - $box[4]) / 2;
$y = (int)($imgY - $box[5]) / 2;
imagettftext($image, $font_size, $angle, $x, $y, $text_col, $font, $_SESSION['rand_code']);
header("Content-type: image/png");
imagepng($image);
imagedestroy ($image);
//Fine Captca code
?>