Utilisation du ReCaptcha de google
Bonjour à tous,
est-ce que quelqu'un a déjà implémenté le reCaptcha de google dans un site webdev ?
J'ai du mal à traduire en WebDev certaine partie de l'algo.
Voici un exemple fonctionnel en php :
Côté navigateur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <html>
<head>
<title>Google recapcha demo - Codeforgeek</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<h1>Google reCAPTHA Demo</h1>
<form id="comment_form" action="form.php" method="post">
<input type="email" placeholder="Type your email" size="40"><br><br>
<textarea name="comment" rows="8" cols="39"></textarea><br><br>
<input type="submit" name="submit" value="Post comment"><br><br>
<div class="g-recaptcha" data-sitekey="=== Your site key ==="></div>
</form>
</body>
</html> |
Côté serveur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the @$%K out</h2>';
} else {
echo '<h2>Thanks for posting comment.</h2>';
}
?> |
Mon souci se trouve côté serveur. Je ne vois pas quelle commande Webdev envoyé pour récupérer $_POST['g-recaptcha-response'].
Pour l'instant j'ai juste créer une page avec le recaptcha et j'ai mis un bouton submit contenant ceci :
Code:
1 2 3 4 5
| si HTTPRequête("https://www.google.com/recaptcha/api/siteverify","","","secret=xxxxxx&response=g-recaptcha-response&remoteip=localhost") ALORS
Trace(HTTPDonneRésultat())
SINON
Erreur("ko")
FIN |
Ma trace me retourne que ma "response" est mauvaise...
Comment traduire côté serveur la récupération de la variable : $_POST['g-recaptcha-response'] ?
Merci de votre aide.
EDIT :
je m'auto-réponds :aie:
Code:
1 2 3 4 5
| si HTTPRequête("https://www.google.com/recaptcha/api/siteverify","","","secret=xxxxxx&response="+PageParamètre("g-recaptcha-response")+"&remoteip=localhost") ALORS
Trace(HTTPDonneRésultat())
SINON
Erreur("ko")
FIN |