2009-08-12 9 views
8

Sto tentando di aggiungere un reCAPTCHA al mio sito, ma continuo a ricevere l'errore incorrect-captcha-sol quando invio la risposta.Hai bisogno di aiuto con reCAPTCHA - continua a non essere corretto-captcha-sol

Qualcuno può dirmi se sono corretto nel fare quanto segue?

Ho un index.php generico, che include contact.php. In contact.php ho inserito il seguente codice:

require_once('recaptchalib.php'); 
$publickey = "XXXX"; 
$privatekey = "XXXX"; 

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

if ($_POST['submit']) { 
    $message = $_POST['message_txt']; 
    $name = $_POST['name_txt']; 
    $email = $_POST['email_txt']; 

$emailBody = $message; 
$to = 'xx'; 
$from = $name.' <'.$email.'>'; 
$subject = 'XX Website Enquiry'; 
$headers = 'From: '.$from; 

$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); 

if ($resp->is_valid) { 
    echo 'captcha correct'; 
    if (mail($to,$subject,$emailBody,$headers)) { 
     //echo 'mail sent'; 
     $confirmation = 'sent'; 
    } 
    else { 
     //echo 'mail not sent'; 
     $confirmation = 'error'; 
    } 
} else { 
    # set the error code so that we can display it. You could also use 
    # die ("reCAPTCHA failed"), but using the error message is 
    # more user friendly 

    $error = $resp->error; 

    echo $error; 
} 

}

Nel mio html ho inserito il CAPTCHA in questo modo:

<form name="contactForm" method="post" action="index.php?id=contact&action=submit#contact"> 
    <tr><td>Name</td><td><div align="right"> 
     <input type="text" name="name_txt" class="input"> 
     </div></td></tr> 
    <tr><td>Email</td><td><div align="right"> 
     <input type="text" name="email_txt" class="input"> 
    </div></td></tr> 
    <tr><td height="10"></td></tr> 
    <tr><td colspan="2">Message</td></tr> 
    <tr><td colspan="2"><textarea name="message_txt" class="textarea" style="width:200px; height:100px"></textarea></td></tr> 
    <tr><td colspan="2"><?php echo recaptcha_get_html($publickey, $error); ?></td></tr> 
    <tr><td colspan="2" style="padding-top:10px;"><input type="image" src="images/header_06.gif" name="submit" value="submit"></td></tr> 
    </form> 

non riesco a vedere che sto facendo qualcosa di sbagliato, ma apprezzerebbe qualsiasi critica costruttiva.

TIA

risposta

19

ho risolto questo, è una delle cose più insolite che ho incontrato, la mia sintassi è stato in precedenza:

<table> 
<form> 
<tr><td></td></tr> 
</form> 
</table> 

ho cambiato questo:

<form> 
<table> 
<tr><td></td></tr> 
</table> 
</form> 

a causa di questo interruttore, improvvisamente il recaptcha_response_field e recaptcha_challenge_field inviano i valori al modulo.

Non riesco a pensare perché questo perché tutte le variabili del modulo MY sono state postate prima dell'interruttore.

Grazie a tutti per i suggerimenti.

7

se stai scrivendo l'assegno due volte - per esempio una volta da JavaScript e una volta tramite php il secondo fallirà come l'API consente solo una soluzione valida per tornare una volta.

Speranza che aiuta, Josh

0

Sei sicuro si sta digitando parole giuste?

questo è da recaptcha website :

Line 1  "true" or "false". True if the reCAPTCHA was successful 
Line 2 if Line 1 is false, then this string will be an error code. reCAPTCHA can 
    display the error to the user (through the error parameter of api.recaptcha.net/challenge). 
    Implementations should not depend on error code names, 
as they may change in the future. 


    Example: If your response looks like this: 

    false 
    **incorrect-captcha-sol** 

    ... you can add '&error=incorrect-captcha-sol' to the challenge request URL, 
and the user will get an error code. 
5

Questo perché il modulo non può essere all'esterno del tr ..... deve essere all'esterno del tavolo ..... la forma non può essere inserita nella tabella, può essere inserita nel td anche se .

2

Nel mio caso, l'errore è stato quello di impostare la forma senza specificare:

method = "POST"

Cheers!

Problemi correlati