l'ho riprovato ora :
index.php
Codice PHP:
<?php
error_reporting(E_ALL);
require_once('captcha.class.php');
session_start();
$captcha=new captcha();
$act=isset($_GET['act']) ? $_GET['act'] : '';
switch($act):
case('img'):
$captcha->offuscamento=3;
$captcha->genera($_GET['stringa']);
break;
case('check'):
if($_SESSION['stringa'] == $_POST['codice']){
echo 'nome: '.$_POST['nome'];
echo '
';
echo 'cognome: '.$_POST['cognome'];
} else
echo 'Il codice non corrisponde all'immagine';
break;
default:
$stringa=$captcha->stringa_casuale();
$_SESSION['stringa']=$stringa;
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?act=check">
<ul style="list-style: none;">
[*]nome: <input type="text" name="nome" />
[*]cognome: <input type="text" name="cognome" />
[*]codice: [img]'.$_SERVER['PHP_SELF'].'?act=img&stringa='.$stringa.'[/img]
[*]inserisci il codice: <input type="text" name="codice" />
[*]<input type="submit" name="invia" value="invia" />
[/list]
</form>';
break;
endswitch;
?>
e qui la classe captcha.class.php:
Codice PHP:
<?php
// Marco Barcaro
// 22/03/2005
//
// questa classe richiede le librerie grafiche GD
//
// Testato con Apache 1.3.33, PHP 4.3.10, GD 2.0.28 su winXP
class captcha {
var $offuscamento = '';
function captcha(){
$this->x=110;
$this->y=30;
$this->font='arial.ttf';
$this->dimensione=20;
}
function stringa_casuale(){
return chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90));
}
function genera($stringa){
$im=imagecreate($this->x,$this->y);
$bianco=imagecolorallocate($im, 255, 255, 255);
$nero=imagecolorallocate($im, 0, 0, 0);
$box=imagettfbbox($this->dimensione, 0, $this->font, $stringa);
imagettftext($im, $this->dimensione, 0, 5, 5+abs($box[5]), $nero, $this->font, $stringa);
$this->offuscamento=$this->offuscamento != NULL ? $this->offuscamento : 0;
$max=ceil(($this->x * $this->y * $this->offuscamento) / 30);
for($i=0;$i<$max;$i++){
$temp_x=rand(1,$this->x);
$temp_y=rand(1,$this->y);
imageline ($im, $temp_x, $temp_y, $temp_x, $temp_y, $nero);
}
for($i=1;$i<$this->y;$i=$i+10){
imageline ($im, 0, $i, $this->x, $i+5, $nero);
}
for($i=1;$i<$this->x;$i=$i+10){
imageline ($im, $i, 0, $i+5, $this->y, $nero);
}
header("content-type: image/jpeg");
imagejpeg($im,"",80);
imagedestroy($im);
}
}
?>
controlla di non avere spazi alla fine dopo il ?>
a me funziona ho riprovato ora