Problema captcha su pagina php

  • Creatore Discussione Creatore Discussione piero60
  • Data di inizio Data di inizio

piero60

Utente Attivo
26 Gen 2015
71
2
8
Salve a tutti, il form allegato funziona perfettamente solo che non è dotato di captcha.
Ho provato ad installare quello di google, viene visto si aggiorna l'immagine con l'apposito simboletto,
però il controllo non avviene, la registrazione parte anche senza riportare nel campo apposito il codice captcha.

Non capisco dove è l'errore, qualcuno è in grado di aiutarmi.

Nel codice ho evidenziato la parte aggiunta con la scritta <!-- PARTE AGGIUNTA --><!-- FINE PARTE AGGIUNTA -->

Grazie a tutti.

PHP:
<?php
$test = "no";

$IE6 = (ereg('MSIE 6',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
$IE7 = (ereg('MSIE 7',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
$IE8 = (ereg('MSIE 8',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
if (($IE6 == 1) || ($IE7 == 1) || ($IE8 == 1)) {
	$vecchio_browser = TRUE;
}
require 'PasswordHash.php';
$hasher = new PasswordHash(8, TRUE);
include_once ('inc/connect.php');
include_once('inc/functions.php');

include_once('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();

if ($_COOKIE['ricordami'] == "yes") {

	header("location: start.php");
} else{


$pagetitle = "Registrazione - ";

	$nome = "";
	$cognome = "";
	$email = "";
	$conferma_email = "";
	$password = "";
	$conferma_password = "";
		

if (isset($_POST['nome'])) {

	$nome = $_POST['nome'];
	$cognome = $_POST['cognome'];
	$email = $_POST['email'];
	$conferma_email = $_POST['conferma_email'];
	$password = $_POST['password'];
	$conferma_password = $_POST['conferma_password'];
	$ip = $_SERVER['SERVER_ADDR'];

	
	$checkmail = mysql_query("SELECT id FROM user WHERE email='$email'");
	$sql_checkmail = mysql_num_rows($checkmail);

	if ((!$nome) || (!$cognome) || (!$email) || (!$conferma_email) || (!$password) || (!$conferma_password)) {
		$errormessage = "Tutti i campi sono obbligatori.";
	} elseif ($email != $conferma_email) {
		$errormessage = "Le email non coincidono.";
	} elseif ($password != $conferma_password) {
		$errormessage = "Le password devono combaciare.";
	} elseif ($sql_checkmail > 0) {
		$errormessage = "Questo indirizzo email è già usato";
	} 

		else {
				$nome = mysql_real_escape_string($nome);
				$cognome = mysql_real_escape_string($cognome);
				$email = mysql_real_escape_string($email);
				$password = mysql_real_escape_string($password);

				$nome = ucfirst($nome);
				$cognome = ucfirst($cognome);			


				$hash = $hasher->HashPassword($password);

				$chiave = md5(uniqid(rand()));

				$sql = mysql_query("INSERT INTO user (nome, cognome, email, password, data_reg, chiave, ip_registrazione)
					VALUES ('$nome', '$cognome', '$email', '$hash', now(), '$chiave', '$ip')")
				or die(mysql_error());
				$id = mysql_insert_id();
				mkdir("user/$id", 0755);

				$sql2 = mysql_query("INSERT INTO personal (id) VALUES (LAST_INSERT_ID())");
				$sql3 = mysql_query("INSERT INTO professional (id) VALUES (LAST_INSERT_ID())");
				$sql3 = mysql_query("INSERT INTO curriculum (id) VALUES (LAST_INSERT_ID())");
			

// Invio mail user

$mail->SetFrom('supporto@xxxx.com', 'Mittente');
$mail->Subject = 'Completa la tua registrazione';
 
// Destinatari
$mail->AddAddress("$email");
$mail->AddCC("web@xxxx.com"); 
$myPhpMailerObj->CharSet = 'UTF-8';
 
// Corpo messaggio
$body .= 'Ciao '.$nome.'<br>';				
$body .= 'La tua registrazione su xxxxx &egrave; quasi completa.<br>';
$body .= 'Per completarla clicca sul link di seguito.<br>';
$body .= '<http://www.xxxx.com/utenti/confirm.php?email='.$email.'&key='.$chiave.'">http://www.xxxx.com/utenti/confirm.php?email='.$email.'&key='.$chiave.'</a><br>';
$body .= 'Se l\'indirizzo non &egrave; cliccabile, copialo ed incollalo nella barra degli indirizzi.';

$mail->MsgHTML($body);
 
// Autenticazione SMTP
$mail->IsSMTP();
$mail->SMTPAuth   = true;
$mail->Host = "smtp.xxxx.com"; // Server SMTP
$mail->Port       = 25;                    // Porta SMTP
$mail->Username   = "supporto@xxxx.com"; // SMTP account username
$mail->Password   = "2015";        // SMTP account password

// Invio Email e controllo esito
if($mail->Send())
{
    $success = "<h2>Un ultimo passo per attivare<br>il tuo account.</h2><br>
	<h4>Controlla la tua casella di posta elettronica<br>e conferma il tuo indirizzo email.
	<br>Attenzione, controlla anche la casella SPAM<br><br>	Ricorda che se scarichi la posta Hotmail, Gmail, ecc. attraverso il tuo client di	posta elettronica, eventuali<br> messaggi SPAM non vengono scaricati sul tuo PC<br>	Se non ricevi nessun messaggio accedi direttamente alla tua casella di posta	Gmail, Hotmail, ecc<br>	e controlla la cartella SPAM vedrai che lo trovi li.	</h4></br>";
	include_once('header.php');
	include_once('msgtouser.php');
	include_once('footer.php');
	$test = "si";
}
else
{
    echo 'Errore: Email non inviata. ' . $mail->ErrorInfo;
}


		}

}	else{
		$nome = "";
		$cognome = "";
		$email = "";
		$conferma_email = "";
		$password = "";
		$conferma_password = "";
	}
}
?>

<?php include_once ('header.php'); ?>

<?php if ($test==no): ?>

<div class="content">
	<h2 class="title">Registrazione utenti</h2>

	<div id="box">

		<form action="signup.php" method="post" id="signup">			
			<div class="field">
				<?php if($vecchio_browser) {?>
				<label class="lbl" for="nome">Nome:</label>
				<?php } ?>
				<input name="nome" type="text" class="edit_field" id="nome" value="<?php print "$nome"; ?>" <?php if(!$vecchio_browser){ ?> placeholder="Nome" <?php } ?> />
			</div>
			<div class="field">
				<?php if($vecchio_browser) {?>
				<label class="lbl" for="nome">Cognome:</label>
				<?php } ?>
				<input name="cognome" type="text" class="edit_field" id="cognome" value="<?php print "$cognome"; ?>" <?php if(!$vecchio_browser){ ?> placeholder="Cognome" <?php } ?> />
			</div>
			<div class="field">
				<?php if($vecchio_browser) {?>
				<label class="lbl" for="nome">Email:</label>
				<?php } ?>
				<input name="email" type="email" class="edit_field" id="email" value="<?php print "$email"; ?>"  <?php if(!$vecchio_browser){ ?> placeholder="Email" <?php } ?> />
			</div>
			<div class="field">
				<?php if($vecchio_browser) {?>
				<label class="lbl" for="nome">Ripeti email:</label>
				<?php } ?>
				<input name="conferma_email" type="email" class="edit_field" id="conferma_email" value="<?php print "$conferma_email"; ?>" <?php if(!$vecchio_browser){ ?> placeholder="Ripeti email" <?php } ?> />
			</div>
			<div class="field">
				<?php if($vecchio_browser) {?>
				<label class="lbl" for="nome">Password:</label>
				<?php } ?>
				<input name="password" type="password" class="edit_field" id="password" <?php if(!$vecchio_browser){ ?> placeholder="Password" <?php } ?> />
			</div>
			<div class="field">
				<?php if($vecchio_browser) {?>
				<label class="lbl" for="nome">Conferma password:</label>
				<?php } ?>
				<input name="conferma_password" type="password" class="edit_field" id="conferma_password" <?php if(!$vecchio_browser){ ?> placeholder="Conferma password" <?php } ?> />
			</div>	
			<div class="errormessage"><?php print($errormessage) ?></div>
			<br>

<!-- PARTE AGGIUNTA -->			
			
<?php

//IL PROBLEMA E' FORSE QUI' ?
$_SESSION['recaptcha'] = $resp;
//////////////////////////////////////

require_once('recaptchalib.php');

// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "xxxxxxxxxxxxxxxxxxxxxx";
$privatekey = "xxxxxxxxxxxxxxxxxxxxx";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "You got it!";
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>			
			
<!-- FINE PARTE AGGIUNTA -->	
			
			<input type="submit" name="reg" value="Registrati">
			<span>Cliccando su "Registrati" dichiari di accettare l'informativa sul trattamento dei dati<br>
			      Se non hai letto l'informativa sotto trovi il collegamento per leggerla.</span>
			
		</form>
	</div>
</div>

<?php else: ?>

<?php endif ?>

<?php include_once('footer.php') ?>
</body>
</html>
 
Si ciric grazie, mi era totalmente sfuggito quando ho modificato il form per inserire il captcha.

Buona serata.
 

Discussioni simili