Access Code Validation Error: directory "../accesscode/" not found. Script will quit now.'; exit; } if ( !is_writable( $captchaDir ) ) { echo 'ErrorAccess Code Validation Error: directory "../accesscode/" is not writeable. Script will quit now.'; exit; } $handle = opendir( $captchaDir ); while ( $captchaFile = readdir($handle) ) { if ( ( substr($captchaFile, 0, 1) != '.' ) && ( substr($captchaFile, 0, 1) != '_' ) && ( !is_dir( '../accesscode' . '/' . $captchaFile ) ) ) { if ( ( filemtime( '../accesscode' . '/' . $captchaFile ) + 600 ) < time() ) { unlink( '../accesscode' . '/' . $captchaFile ); } } } closedir( $handle ); $handle = @fopen( '../accesscode' . '/' . $fileName, 'w' ); if ( !$handle ) { echo 'ErrorAccess Code Validation Error: unable to create captcha control file. Script will quit now.'; exit; } fclose($handle); if (imagetypes() & IMG_JPG) { header('Content-type: image/jpeg'); imagejpeg($im); } elseif (imagetypes() & IMG_PNG) { header('Content-type: image/png'); imagepng($im); } exit; } function DoStripSlashes($fieldValue) { // temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6 if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) { if (is_array($fieldValue) ) { return array_map('DoStripSlashes', $fieldValue); } else { return trim(stripslashes($fieldValue)); } } else { return $fieldValue; } } function FilterCChars($theString) { return preg_replace('/[\x00-\x1F]/', '', $theString); } function CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars, $optional) { $regEx = ''; if ($limitAlpha == kYes) { $regExp = 'A-Za-z'; } if ($limitNumbers == kYes) { $regExp .= '0-9'; } if ($limitEmptySpaces == kYes) { $regExp .= ' '; } if (strlen($limitExtraChars) > 0) { $search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|', '/'); $replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|', '\/'); $regExp .= str_replace($search, $replace, $limitExtraChars); } if ( (strlen($regExp) > 0) && (strlen($value) > 0) ){ if (preg_match('/[^' . $regExp . ']/', $value)) { return false; } } if ( (strlen($value) == 0) && ($optional === kOptional) ) { return true; } elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) { return true; } elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) { return true; } elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) { return true; } else { return false; } } function CheckEmail($email, $optional) { if ( (strlen($email) == 0) && ($optional === kOptional) ) { return true; } elseif ( preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $email) == 1 ) { return true; } else { return false; } } function CheckFTGCaptcha($accessCode) { $captchaDir = '../accesscode'; if ( !is_dir( $captchaDir ) ) { echo 'ErrorAccess Code Validation Error: directory "../accesscode/" not found. Script will quit now.'; exit; } $handle = opendir( $captchaDir ); $fileAccessCode = substr( md5( $accessCode ), 0, 12 ); while ( $captchaFile = readdir( $handle ) ) { if ( substr( $captchaFile, 0, 1 ) != '.' ) { if ( $fileAccessCode == $captchaFile ) { return true; } } } return false; } function DeleteCaptcha($accessCode) { $captchaDir = '../accesscode'; if ( !is_dir( $captchaDir ) ) { echo 'ErrorAccess Code Validation Error: directory "../accesscode/" not found. Script will quit now.'; exit; } $handle = opendir( $captchaDir ); $fileAccessCode = substr( md5( $accessCode ), 0, 12 ); while ( $captchaFile = readdir( $handle ) ) { if ( ( substr( $captchaFile, 0, 1 ) != '.' ) && ( substr( $captchaFile, 0, 1 ) != '_' ) && ( !is_dir( '../accesscode' . '/' . $captchaFile ) ) ) { if ( $fileAccessCode == $captchaFile ) { unlink( '../accesscode' . '/' . $captchaFile ); return; } } } } if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $clientIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $clientIP = $_SERVER['REMOTE_ADDR']; } if ( isset($_GET['formstogoimgflt']) ) { CaptchaGenerator(); exit; } $FTGnome = DoStripSlashes( $_POST['nome'] ); $FTGtelefono = DoStripSlashes( $_POST['telefono'] ); $FTGemail = DoStripSlashes( $_POST['email'] ); $FTGsoggetto = DoStripSlashes( $_POST['soggetto'] ); $FTGmessaggio = DoStripSlashes( $_POST['messaggio'] ); $FTGprivacy = DoStripSlashes( $_POST['privacy'] ); $FTGconsenso = DoStripSlashes( $_POST['consenso'] ); $FTGaccesscode = DoStripSlashes( $_POST['accesscode'] ); $FTGnome = strip_tags($FTGnome); $FTGtelefono = strip_tags($FTGtelefono); $FTGemail = strip_tags($FTGemail); $FTGsoggetto = strip_tags($FTGsoggetto); $FTGmessaggio = strip_tags($FTGmessaggio); $FTGprivacy = strip_tags($FTGprivacy); $FTGconsenso = strip_tags($FTGconsenso); $FTGaccesscode = strip_tags($FTGaccesscode); $validationFailed = false; # Fields Validations if (!CheckString($FTGnome, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) { $validationFailed = true; } if (!CheckString($FTGtelefono, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) { $validationFailed = true; } if (!CheckEmail($FTGemail, kMandatory)) { $validationFailed = true; } if (!CheckString($FTGmessaggio, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) { $validationFailed = true; } if (!CheckString($FTGprivacy, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) { $validationFailed = true; } if (!CheckString($FTGconsenso, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) { $validationFailed = true; } if (!CheckFTGCaptcha($FTGaccesscode)) { $validationFailed = true; } # Redirect user to the error page if ($validationFailed === true) { header("Location: http://www.fercoservizi.com/index.php?a=contatti&do=nok"); } if ( $validationFailed === false ) { # Email to Form Owner $emailSubject = FilterCChars("Modulo WEB richiesta informazioni da $FTGnome"); $emailBody = chunk_split( base64_encode( "\n" . "\n" . "\n" . "\n" . "\n" . "Il giorno " . date('d/m/Y') . " hai rivevuto un contatto da:
\n" . "nome : $FTGnome
\n" . "telefono : $FTGtelefono
\n" . "email : $FTGemail
\n" . "soggetto : $FTGsoggetto
\n" . "messaggio : " . nl2br( $FTGmessaggio ) . "
\n" . "privacy : $FTGprivacy
\n" . "Consenso : $FTGconsenso
\n" . "\n" . "\n" . "\n" . "" ) ) . "\n"; $emailTo = 'info@fercoservizi.com'; $emailFrom = FilterCChars("$FTGemail"); $emailHeader = "From: $emailFrom\n" . 'Cc: commerciale@fercoservizi.com' . "\n" . "MIME-Version: 1.0\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: base64\n" . "\n"; mail($emailTo, $emailSubject, $emailBody, $emailHeader); DeleteCaptcha($FTGaccesscode); # Redirect user to success page header("Location: http://www.fercoservizi.com/index.php?a=contatti&do=ok"); } ?>