File ramdom.php

Codice PHP:
<?php 
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(97122)); 
    } 
    
$_SESSION['rand_code'] = $str


$imgX 60
$imgY 20
$image imagecreatetruecolor(6020); 

$backgr_col imagecolorallocate($image238,239,239); 
$border_col imagecolorallocate($image208,208,208); 
$text_col imagecolorallocate($image46,60,31); 

imagefilledrectangle($image006020$backgr_col); 
imagerectangle($image005919$border_col); 

$font "C:\WINDOWS\Fonts\ARIAL.TTF"// it's a Bitstream font check [url]www.gnome.org[/url] for more 
$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); 

?>
Input page:
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<input type="text" name="validator" id="validator" size="4" /> 
[img]random.php[/img] 
<?php 
if (!empty($_POST['validator']) && $_POST['validator'] == $_SESSION['rand_code']) { 
   
    unset(
$_SESSION['rand_code']); 

}
?> 

</body>
</html>
Questa riga la devi adattare al path del server
$font = "C:WINDOWSFontsARIAL.TTF";