ciao ho questo codice che genera un'immagine e dovrebbe aprirmi una sessione
Codice PHP:
<?php
session_start();
class CaptchaSecurityImages {
var $font = 'georgia.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='4') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.60;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 33, 33, 33);
$text_color = imagecolorallocate($image, 152, 125, 80);
$noise_color = imagecolorallocate($image, 50, 50, 50);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '4';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
e questo codice nella pagina di invio di una mail che dovrebbe controllare il captcha
Codice PHP:
<?php
echo "codice:".$_SESSION['security_code'];
include_once('PHPMailer/class.phpmailer.php');
$nome=$_REQUEST['nome'];
$cognome=$_REQUEST['cognome'];
$indirizzo=$_REQUEST['indirizzo'];
$localita=$_REQUEST['localita'];
$cap=$_REQUEST['cap'];
$prov=$_REQUEST['prov'];
$email=$_REQUEST['email'];
$telefono=$_REQUEST['telefono'];
$oggetto_mail=$_REQUEST['oggetto'];
$messaggio=$_REQUEST['messaggio'];
$accettaprivacy=$_REQUEST['accettaprivacy'];
$validazione=$_REQUEST['validazione'];
$validazione_ok=$_SESSION['security_code'];
$indirizzo = $indirizzo.' - '.$cap.' '.$localita.'('.$prov.')';
if($validazione==$validazione_ok){
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
if (trim($email) == ""){
echo "<h2>l'e-mail è un campo obbligatorio! - [url='javascript:history.back();']torna[/url]</h2>";
}
elseif (trim($messaggio) == ""){
echo "<h2>il messaggio è un campo obbligatorio! - [url='javascript:history.back();']torna[/url]</h2>";
}
elseif (trim($accettaprivacy) != "accetto"){
echo "<h2>per inviare la mail devi accettare la normativa sulla privacy - [url='javascript:history.back();']torna[/url]</h2>";
}
else {
$mittente=$email;
if ($oggetto_mail==""){
$oggetto="richiesta informazioni dal sito castramaiora.it";
}
else {
$oggetto=$oggetto_mail;
}
#
$corpo=
#
#
#
# INVIO MAIL
#mail("paololosco@gmail.com", $oggetto, $messaggio, $header);
$mail = new PHPMailer();
$mail->From = $mittente;
$mail->FromName = "".$nome." ".$cognome."";
$mail->Subject = $oggetto;
$html_body ='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title></title>
</head>
<body style="margin: 0; padding: 0; text-align: center; width: 100%; background:#000; color:#ccc;">
<div style="width:550px; margin:0 auto; font-family: Verdana, Arial, Helvetica, sans-serif;">
<table cellpadding="5" cellspacing="5" width=550 style="border:0; margin: 5px auto; text-align: left; background: #212121">
<tr>
<td colspan="2">
<h1 style="font-family: \'Times New Roman\', Times, serif; letter-spacing: -1px; line-height: 24px; font-size:22px; text-align: left; margin: 10px 0 2px 0; color: #987d50; font-weight: normal;">'.$oggetto.'</h1>
</td>
</tr>
<tr>
<td width="120" style="padding-top: 30px; text-align: right;">
nome:
</td>
<td style="padding-top: 30px;">
'.$nome.' '.$cognome.'
</td>
</tr>
<tr>
<td width="120" style="padding-top: 10px; text-align: right;">
email:
</td>
<td style="padding-top: 10px;">
'.$email.'
</td>
</tr>
<tr>
<td width="120" style="padding-top: 10px; text-align: right;">
indirizzo:
</td>
<td style="padding-top: 10px;">
'.$indirizzo.'
</td>
</tr>
<tr>
<td width="120" style="padding-top: 10px; text-align: right;">
telefono:
</td>
<td style="padding-top: 10px;">
'.$telefono.'
</td>
</tr>
<tr>
<td width="120" style="padding-top: 30px; text-align: right;">
oggetto:
</td>
<td style="padding-top: 30px;">
<h1 style="font-family: \'Times New Roman\', Times, serif; letter-spacing: -1px; line-height: 24px; font-size:22px; text-align: left; margin: 10px 0 2px 0; color: #987d50; font-weight: normal;">'.$oggetto.'</h1>
</td>
</tr>
<tr>
<td width="120" style="padding-top: 10px; text-align: right;">
richiesta:
</td>
<td style="padding-top: 10px;">
'.$messaggio.'
</td>
</tr>
</table>
</div>
</body>
</html>
';
$mail->MsgHTML($html_body);
$mail->AddAddress("paololosco@gmail.com");
$nome_intero=''.$nome.' '.$cognome.'';
if ($mail->Send())
{
echo "<h2>la mail è stata inviata correttamente a</h2>";
}
else
{
echo 'Errore: mail non inviata - [url="javascript:history.back();"]torna[/url]';
}
}
}
else{
echo "<h2>la mail inserita non è un indirizzo valido! - [url='javascript:history.back();']torna[/url]</h2>";
}
}
else{
echo "<h2>il codice di validazione inserito non è corretto! - [url='javascript:history.back();']torna[/url]</h2>";
}
?>
quello che mi risulta è: se scrivo il codice corretto NON va, se lascio vuoto SI...
ho provato a stampare la sessione e mi da il vuoto...
il bello è che lo stesso identico script, sullo stesso server ma in un altro sito va a meraviglia...
idee?