Codice:
<?php
session_start();
define("NONE", 0);
define("EASY", 30);
define("MEDIUM", 50);
define("HARD", 80);
define("VERY_HARD", 100);
define("POINT", 1);
define("LINE", 2);
/* dimensioni */
$x = 220; //larghezza
$y = 100; //altezza
$image = imagecreatetruecolor($x, $y); //creo l'immagine
$color = array();
$color[] = imagecolorallocate($image, 255, 0, 0);
$color[] = imagecolorallocate($image, 0, 255, 0);
$color[] = imagecolorallocate($image, 0, 0, 255);
$color[] = imagecolorallocate($image, 255, 255, 0);
$color[] = imagecolorallocate($image, 255, 0, 255);
$color[] = imagecolorallocate($image, 255, 255, 255);
$color[] = imagecolorallocate($image, 0, 255, 255);
$font = array();
//$font[] = "font/arial.ttf";
$font[] = "font/abbeyroad_regular.ttf";
//$font[] = "font/roman_sd_regular.ttf";
$font[] = "font/elephants_in_cherry_trees_normal.ttf";
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $black);
add_noise($image, EASY, LINE, $x, $y); //aggiungo il disturbo
$_SESSION['CAPTCHA'] = strtolower(getString()); //genero la nuova stringa
for($i = 0;$i < strlen($_SESSION['CAPTCHA']); $i++) {
/* per ogni lettera applico impostazioni diverse (dimensione, angolo, colore, font) */
imagettftext(
$image, //immagine
20 + rand(0, 6), //dimensione carattere
rand(-35, 35), //angolo di rotazione
($i+1)*26, //offset sulla x
45+ rand(0, 4), //offset sulla y
$color[rand(0, count($color)-1)], //colore
$font[rand(0, count($font)-1)], //carattere
$_SESSION['CAPTCHA'][$i] //lettera da stampare
);
}
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
function getString() {
$str = base64_encode(time());
$str = str_replace("=", "", $str); //elimino gli =
$str = str_shuffle($str);
return substr($str, 0, 6);
}
function add_noise($image, $difficoult, $figure, $x, $y) {
if($figure == 1)
$difficoult *= 5; //i punti devono essere più delle linee per generare un disturbo significativo
for($i = 0; $i < $difficoult; $i++) {
$color = imagecolorallocate($image, rand(0,255), rand(0,255), rand(0,255));
$p = rand(0, 10);
$x1 = rand($p, rand($x - $p, $x-1));
$x2 = rand($p, rand($x - $p, $x-1));
$y1 = rand($p, rand($y - $p, $y-1));
$y2 = rand($p, rand($y - $p, $y-1));
switch($figure) {
case 1:
imageline($image, $x1, $y1, $x1, $y1, $color);
break;
default:
imageline($image, $x1, $y1, $x2, $y2, $color);
break;
}
}
}
?>
e questo il codice dello script ke fa il controllo sul form ed al quale dovrei inserire anke il controllo sul captcha ma nn ci riesco!:
Codice:
<?php
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
if ($action == "send")
{
include("config.php");
$to = $ademail;
$from = $_POST['from'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = trim($to);
$from = trim($from);
$name = trim($name);
$subject = trim($subject);
$message = trim($message);
if (empty($to))
{
$ermessage = "Error: Email address to can not be blank, Please enter your email address in the config file!";
include("contattamifallito.html"); exit();
}
if (empty($from))
{
$ermessage = "Error: Email address can not be blank, Please enter your email address!";
include("contattamifallito.html"); exit();
}
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $from))
{
$ermessage = "Error: Invalid Email address, Please re-enter your email address!";
include ("contattamifallito.html"); exit;
}
if (empty($name))
{
$ermessage = "Error: Please enter your name!";
include("contattamifallito.html"); exit();
}
if (empty($subject))
{
$ermessage = "Error: Subject can not be blank, Please enter email subject";
include("contattamifallito.html"); exit();
}
if (empty($message))
{
$ermessage = "Error: Message body can not be blank, Please enter email message";
include("contattamifallito.html"); exit();
}
//controllo captcha
if(isset($cpt) && !empty($cpt)){
if($_SESSION['CAPTCHA'] != strtolower($_POST['cpt'])){
$ermessage = "Error: Invalid Code";
include("contattamifallito.html"); exit();}
}//fine
$message = $message;
$send = mail($to, $subject, "From: {$from} Nome: {$name}", $message);
if ($send)
{
include("email_sent.htm"); exit();
}
else
{
$ermessage = "Error: You message has not been sent, please try again";
include("contattamifallito.html"); exit();
}
}
else
{
include("contattami.html");
}
?>
senza il captcha funziona bene inviando i dati del form alla mail....ma nn il captcha non funziona!sapreste aiutarmi??