Mandatory captcha installation
depaninf
Posted messages
154
Status
Member
-
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
Hello,
I've been getting a lot of spam from the contact page of my site for some time now. So I installed a captcha but I couldn't make it mandatory...
I've read the instructions but I'm struggling... I need step-by-step help.
Between the two head tags, I added the client-side integration:
And where I want the captcha, I added
The server-side integration is missing but I don't know how to do it...
Can someone help me? :)
Thank you
I've been getting a lot of spam from the contact page of my site for some time now. So I installed a captcha but I couldn't make it mandatory...
I've read the instructions but I'm struggling... I need step-by-step help.
Between the two head tags, I added the client-side integration:
<script src='https://www.google.com/recaptcha/api.js' async defer></script>
And where I want the captcha, I added
<div class="g-recaptcha" data-sitekey="my_site_key"></div>
The server-side integration is missing but I don't know how to do it...
Can someone help me? :)
Thank you
4 answers
-
Hello,
To start, you need to show us the complete code of your form.
Then, the PHP code that processes the data from this form.
You can, by the way, do aprint_r($_POST);
at the beginning of your PHP code to see what recaptcha returns in case of a good or bad response.
You should have a variable like g-recaptcha-response... that's the one that will allow you to know if the user validated the captcha or not.
--
Best regards,
Jordane-
Good evening Jordane, and thank you for your response.
I didn't understand how to do theprint_r($_POST);
so I'm posting the complete code of the page.
On the PHP side, I don't have any lines with a variable like g-recaptcha-response. I have a bat folder containing rd-mailform.php and a phpmailer folder, inside the phpmailer folder I have 4 php files: class.phpmailer; class.pop3; class.smtp and PHPMailerAutoload. Which one should I send you?
Thank you again for your help!
Here is the HTML code of the page:
<!DOCTYPE html> <html lang="fr"> <html xmlns:og="http://ogp.me/ns#"> <head> <title>SOS Dépannage informatique: pour nous contacter</title> <meta charset="utf-8"> <meta property="og:title" content="SOS Dépannage Informatique: dépannage d'ordinateurs sur site à Paris et sa région"> <meta property="og:locale" content="fr_FR"> <meta property="og:type" content="website"> <meta property="og:url" content="https://www.sosdepaninformatique.com/"> <meta property="og:image" content="https://www.sosdepaninformatique.com/images/reseau2.jpg"> <meta property="og:site_name" content="SOS Dépannage Informatique"> <meta property="og:description" content="Dépannage informatique à domicile et sur site pour particuliers, artisans et entreprises à Paris et en région parisienne. 06 21 43 06 15 du lun à sam 9h à 22h."> <meta property="og:image:alt" content="dépannage informatique à Créteil"> <meta property="fb:app_id" content="249991368794737"> <meta property="fb:admins" content="113574806021696"> <meta name="twitter:description" content=" Dépannage informatique à domicile et sur site pour particuliers, artisans et entreprises à Paris et en région parisienne. 06 21 43 06 15 du lun à sam 9h à 22h."> <meta name="twitter:title" content=" SOS Dépannage Informatique: dépannage d'ordinateurs sur site à Paris et sa région"> <meta name="twitter:card" content="summary"> <meta name="format-detection" content="telephone=no"> <meta http-equiv="Content-Language" content="fr"> <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> <met <meta charset="utf-8"> <meta property="og:title" content="SOS Dépannage Informatique: dépannage d'ordinateurs sur site à Paris et sa région"> <meta property="og:locale" content="fr_FR"> <meta property="og:type" content="website"> <meta property="og:url" content="https://www.sosdepaninformatique.com/"> <meta property="og:image" content="https://www.sosdepaninformatique.com/images/reseau2.jpg"> <meta property="og:site_name" content="SOS Dépannage Informatique"> <meta property="og:description" content="Dépannage informatique à domicile et sur site pour particuliers, artisans et entreprises à Paris et en région parisienne. 06 21 43 06 15 du lun à sam 9h à 22h."> <meta property="og:image:alt" content="dépannage informatique à Créteil"> <meta property="fb:admins" content="113574806021696"> <meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@SDI_Depan_info"> <meta name="twitter:title" content=" SOS Dépannage Informatique: dépannage d'ordinateurs sur site à Paris et sa région"> <meta name="twitter:description" content="Dépannage informatique à domicile et sur site pour particuliers et entreprises à Paris et en région parisienne. 06 21 43 06 15."> <meta name="twitter:creator" content="@SOS Dépannage Info"> <meta name="twitter:image" content="https://www.sosdepaninformatique.com/images/reseau3.jpg"> <meta name="format-detection" content="telephone=no"> <meta http-equiv="Content-Language" content="fr"> <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> <meta content="text/html; charset=utf-8" http-equiv="content-type"> <meta name="title" content="SOS Dépannage Informatique : pour nous contacter !"/> <meta name="description" content="Contactez votre dépanneur informatique à domicile et sur site pour particuliers et entreprises à Paris et en région parisienne. Assistance informatique."/> <meta name="keywords" content="dépannage informatique à domicile, réparation ordinateur et PC à paris, depannage pme artisans entreprises particuliers, maintenance réseaux et assistance informatique, contact, adresse, mail, téléphone, plan d'accès, email, coordonnées"/> <meta name="author" content="SOS Dépannage Informatique, dépannage Créteil"/> <meta name="identifier-url" content="https://www.sosdepaninformatique.com"/> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="icon" href="images/favicon.ico" type="image/x-icon"> <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"> <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="stylesheet" href="css/mailform.css"/> <link rel="stylesheet" href="css/grid.css"> <link rel="stylesheet" href="css/style.css"> <link rel="canonical" href="https://www.sosdepaninformatique.com/"> <link rel="dns-prefetch" href="//ajax.googleapis.com"> <link rel="dns-prefetch" href="//www.sosdepaninformatique.com"> <link rel="dns-prefetch" href="//s.w.org"> <script src="js/jquery.js"></script> <script src="js/jquery-migrate-1.2.1.js"></script> <script src='js/device.min.js'></script> <script src='https://www.google.com/recaptcha/api.js' async defer></script> </head> <body> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-4195061-2', 'auto'); ga('send', 'pageview'); </script> </head> <body> <div class="page"> <!--======================================================== HEADER =========================================================--> <header> <div class="well"> <div class="container"> <div class="brand"> <span class="brand_name"> <a href="https://www.sosdepaninformatique.com/" title="Dépannage informatique sur site">SOS <span>Dépannage Informatique</span></a> </div> <div class="contacts"> <a href="tel:+33621430615" title="Appelez-nous">06 21 43 06 15</a> <dl> <dt>Heures d'ouverture</dt> <dd>Lun-Sam 9:00 à 22:00</dd> </dl> </div> </div> </div> <div id="stuck_container" class="stuck_container"> <nav class="nav"> <div class="container"> <ul class="sf-menu" data-type="navbar"> <li class="active"> <a href="https://www.sosdepaninformatique.com/" title="Accueil SDI">Accueil</a> </li> <li> <a href="a-propos.html" title="Présentation SDI">Présentation</a> </li> <li> <a href="services.html" title="Nos services">Services</a> <ul> <li> <a href="services.html#depannage-courant" title="Maintenance informatique">Dépannage informatique</a> </li> <li> <a href="services.html#reseaux" title="Réseau et serveur informatique">Réseaux et sécurité</a> </li> <li> <a href="services.html#formation" title="Formation bureautique et Windows">Formation</a> </li> <li> <a href="services.html#sites-internet" title="Réalisation de Site Internet et Boutiques en ligne">Création de sites, Boutiques</a> </li> <li> <a href="services.html#sauvegarde" title="Sauvegarde de vos données">Sauvegardes en ligne</a> </li> <li> <a href="services.html#sauvegarde" title="Récupération de données">Récupération de données</a> </li> <li> <a href="index.html#diagnostic" title="Réparation à distance">Assistance à distance</a> </li> <li> <a href="services.html#materiel-info" title="Matériel, logiciels informatique et composants">Vente de matériel</a> </li> <li> <a href="services.html#cameras" title="Caméras de surveillance IP">Caméras de surveillance IP</a> </li> </ul> </li> <li> <a href="comprendre.html" title="Pour nous comprendre">Comprendre</a> <ul> <li> <a href="lexique" title="Lexique des mots informatiques">Lexique</a> </li> <li> <a href="glossaire" title="Glossaire des mots courants">Glossaire 2017</a> </li> </ul> </li> <li> <a href="tarifs-entreprises" title="Nos tarifs pour les professionnels">Tarifs entreprises</a> </li> <li> <a href="tarifs-particuliers" title="Nos tarifs pour les particuliers">Tarifs particuliers</a> </li> <li> <a href="temoignages.html" title="Vos témoignages">Vos témoignages</a> </li> <li> <a href="contact.html" title="Contactez-nous">Contact</a> </li> </ul> </div> </nav> </div> </header> <!--======================================================== CONTENT =========================================================--> <main> <section class="well-4 well-4__off divider-xs well-xs-1"> <div class="container"> <h1><strong>Contactez SDI</strong> votre dépanneur informatique sur site</h1> <div class="row row__off-2"> <div class="col-md-4 col-sm-4 col-xs-12"> <font size="6" color="#333333" face="Raleway sans-serif">Formulaire de contact</font><br> <br><address class="addr"><p class="h2">20 rue Claude Nicolas Ledoux<br/> 94000 Créteil</h2></p> <dl> <h2>Téléphone : <a href="tel:+33621430615" title="Appelez-nous">06 21 43 06 15</a></h2> </dl> <dl> <br> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2629.8211336673157!2d2.4683823156711364!3d48.766211979278516!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xd1c5a5ceed3072d7!2sSOS+D%C3%A9pannage+Informatique!5e0!3m2!1sfr!2sus!4v1499367345408" width="260" height="220" frameborder="0" style="border:0" allowfullscreen></iframe> </dl><br> <p><dl> <h2>Zone d'intervention :<br> Paris et Région parisienne</h2></p> </dl> <br/> </address> </div> <div class="col-md-8 col-sm-8 col-xs-12"> <font size="6" color="#333333" face="Raleway sans-serif">Formulaire de contact</font><br> <br><form class='mailform' method="post" action="bat/rd-mailform.php"> <input type="hidden" name="form-type" value="contact"/> <fieldset> <div class="mail-wrap"> <label data-add-placeholder> <input type="text" name="name" placeholder="Nom*:" data-constraints="@LettersOnly @NotEmpty"/> </label> <label data-add-placeholder> <input type="text" name="email" placeholder="E-mail*:" data-constraints="@Email @NotEmpty"/&> </label> <label data-add-placeholder> <input type="text" name="phone" placeholder="Téléphone*:" data-constraints="@Phone @NotEmpty"/> </label> </div> <label data-add-placeholder> <textarea name="message" placeholder="Commentaires*:" data-constraints="@NotEmpty"></textarea> </label> <div class="g-recaptcha" data-sitekey="********"></div> <div class="mfControls"> <button class="btn-primary" title="Envoyez-nous votre message" type="submit">Soumettre</button> </div> <p>*requis</p><br/> </fieldset> </form> </div> </div> </div> </section> </main> <!--======================================================== FOOTER =========================================================--> <footer class="footer-wrap"> <section> <div class="container"> <div class="row"> <div class="col-md-4 col-sm-6"> <h5>A propos</h5> <br><p><strong>SOS Dépannage Informatique</strong> est née de l'expérience acquise le plus souvent sur le terrain tout au long des 20 dernières années.</p> <p>Aguerris à l'outil informatique et aux nouvelles technologies, nous-nous proposons de partager ces connaissances avec nos partenaires.</p> <p>Que vous soyez un professionnel ou un particulier, <strong>SDI</strong> met un expert à votre service et vous donnera entière satisfaction.</p> <p>Une heure d'intervention suffit bien souvent à régler les petits soucis courants.</p> </div> <div class="col-md-4 col-sm-6"> <h5>Contact</h5> <address class="footer-term-list"> <br><p><span class="font-primary">Adresse:</span> 20 rue Claude Nicolas Ledoux 94000 Créteil</p> <dl> <dt class="font-primary"> Téléphone: </dt> <dd> <a href="tel:+*******" title="Appelez-nous" class="phone fa-phone">06 21 43 06 15</a> </dd> <dt class="font-primary">Heures d'ouverture:</dt> <dd>Lun-Sam 9:00 à 22:00</dd> </dl> <dl> <dt class="font-primary"> <p></p> <p><a href="********/" title="SOS Dépannage Informatique copyright">SOS <span>Dépannage Informatique © 2005 - <span id="copyright-year"></span></span></a></p> </dt> <p><br> <br> <a href="http://www.facebook.com/sharer.php?u=https://www.facebook.com/sosdepannageinformatique/&t=Service+de+d%C3%A9pannage+informatique+sur+site+accessible+%C3%A0+Paris+et+en+r%C3%A9gion+parisienne" rel="nofollow noopener noreferrer" target="_blank"><img src="reseaux/facebook.png" alt="Facebook" height="36" width="36"></a> <a href="https://www.pagesjaunes.fr/contribution/avis_flow/09372230/create?codeRubrique=26100300rel=" nofollow=" " noopener=" ", noreferrer=" " target="_blank"><img src="reseaux/pagesjaunes.png" alt="Pages_jaunes" height="36"width="36"></a> <a href="http://twitter.com/share?url=https://twitter.com/SDI_Depan_info/&text=Service+de+d%C3%A9pannage+informatique+sur+site+accessible+%C3%A0+Paris+et+en+r%C3%A9gion+parisienne" rel="nofollow noopener noreferrer" target="_blank"><img src="reseaux/twitter.png" alt="Twitter" height="36" width="36"></a> <a href="https://www.instagram.com/sos_depannage_informatique/" rel="nofollow noopener noreferrer" target="_blank"><img src="reseaux/instagram.png" alt="Instagram" height="36" width="36"></a> <a href="https://www.linkedin.com/cws/share?token&isFramed=false&url=https://www.linkedin.com/in/sosdepannageinformatique/&title=Service+de+d%C3%A9pannage+informatique+sur+site+accessible+%C3%A0+Paris+et+en+r%C3%A9gion+parisienne" rel="nofollow noopener noreferrer" target="_blank"><img src="reseaux/linkedin.png" alt="Linkedin" height="36" width="36"></a> <a href="https://plus.google.com/share?url=https://plus.google.com/u/0/collection/osiBTE" rel="nofollow noopener noreferrer" target="_blank"><img src="reseaux/google-plus.png" alt="Google+" height="36" width="36"></a> <a href="https://goo.gl/maps/GxT5q6K8X7C2" rel="nofollow noopener noreferrer" target="_blank"><img src="reseaux/google-maps.png" alt="Google-Maps" height="36" width="36"></a></p><br/> <br> </dl> </address> </div> <div class="col-md-4 col-sm-12"> <h5>Liens internes</h5> <address class="footer-term-list"> <ul class="marked-list offset"> <p></p> <br><li><a href="temoignages" title="Vos témoignages clients">Vos témoignages</a> </li> <li class="item"> <a href="lexique" title="Lexique">Lexique</a> </li> <li class="item"> <a href="glossaire" title="Glossaire">Glossaire</a></li> <li class="item"> <a href="partenaires" title="Partenaires">Partenaires</a></li> <li class="item"> <a href="mentions-legales" title="Mentions légales SDI">Mentions légales</a><br/> </li> <li class="item"> <a href="sitemap" title="Sitemap de SDI">Sitemap</a><br/> </li> <li class="item"> <a href="conditions-generales-de-vente" title="Conditions générales de vente">Conditions générales de vente</a><br/> </li> </ul> <p></p> </address> </div> </div> </div> </section> </footer> </div> <script src="js/script.js"></script> </body> </html> -
-
-
-
-
Sure, here it is :)
<?php $recipients = 'depaninf@sosdepaninformatique.com'; //$recipients = '#'; try { require './phpmailer/PHPMailerAutoload.php'; preg_match_all("/([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)/", $recipients, $addresses, PREG_OFFSET_CAPTURE); if (!count($addresses[0])) { die('MF001'); } if (preg_match('/^(127\.|192\.168\.)/', $_SERVER['REMOTE_ADDR'])) { die('MF002'); } $template = file_get_contents('rd-mailform.tpl'); if (isset($_POST['form-type'])) { switch ($_POST['form-type']){ case 'contact': $subject = 'You have a visitor message'; break; case 'subscribe': $subject = 'Subscribe request'; break; case 'order': $subject = 'Order request'; break; default: $subject = 'You have a visitor message'; break; } }else{ die('MF004'); } if (isset($_POST['email'])) { $template = str_replace( ["<!-- #{FromState} -->", "<!-- #{FromEmail} -->"], ["Email:", $_POST['email']], $template); }else{ die('MF003'); } if (isset($_POST['message'])) { $template = str_replace( ["<!-- #{MessageState} -->", "<!-- #{MessageDescription} -->"], ["Message:", $_POST['message']], $template); } preg_match("/(<!-- #{BeginInfo} -->)(.|\n)+(<!-- #{EndInfo} -->)/", $template, $tmp, PREG_OFFSET_CAPTURE); foreach ($_POST as $key => $value) { if ($key != "email" && $key != "message" && $key != "form-type" && !empty($value)){ $info = str_replace( ["<!-- #{BeginInfo} -->", "<!-- #{InfoState} -->", "<!-- #{InfoDescription} -->"], ["", ucfirst($key) . ':', $value], $tmp[0][0]); $template = str_replace("<!-- #{EndInfo} -->", $info, $template); } } $template = str_replace( ["<!-- #{Subject} -->", "<!-- #{SiteName} -->"], [$subject, $_SERVER['SERVER_NAME']], $template); $mail = new PHPMailer(); $mail->From = $_SERVER['SERVER_ADDR']; $mail->FromName = $_SERVER['SERVER_NAME']; foreach ($addresses[0] as $key => $value) { $mail->addAddress($value[0]); } $mail->CharSet = 'utf-8'; $mail->Subject = $subject; $mail->MsgHTML($template); if (isset($_FILES['attachment'])) { foreach ($_FILES['attachment']['error'] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $mail->AddAttachment($_FILES['attachment']['tmp_name'][$key], $_FILES['Attachment']['name'][$key]); } } } $mail->send(); die('MF000'); } catch (phpmailerException $e) { die('MF254'); } catch (Exception $e) { die('MF255'); } ?>
EDIT: Added syntax highlighting-
-
NB: When posting your code on the forum, remember to indicate the LANGUAGE in the code tags to have syntax highlighting.
Explanations provided here: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code -
-
-
-
-
The error is related to the fact that your form is called via Ajax and that print_r displays information that is not encoded in JSON.
Looking in the browser's CONSOLE, you can see that print_r returns the expected information, namely:Array ( [form-type] => contact [name] => aa [email] => test@gg.com [phone] => 0123456789 [message] => azaz [g-recaptcha-response] => 03AMGVjXg4dKjinxK16Hi2MEhi-NfDiMQNdq8E4ZCFcey5ZlS_WeibJj0QgSH0W5evzZ1Me4xaAhPmVN1tH1UzNIQ5aLb_7etUOR8anqimg3fdMX83okoQKjQUKAlxyykZdfUh0oc-I-jYkNmkZSrOKmUsbpvugYEf7ERW7K2-YbtK9hfG9y7rSENukCrsD3nBUYLmIVJwwwMwNcQEYBSDB1EvqM9UJCYVh5lVNYJkn3AZ8T7RNdPHzTgw8iAeergJ7f5seoes3WR-b0cPswch7_hqmurVNdFxbajgNV68Xi7SbI5ApvKBErc ) MF000
As you can see, there is indeed a variable g-recaptcha-response
and when the captcha is not checked, we get:Array ( [form-type] => contact [name] => aaa [email] => gg@test.com [phone] => 0123456789 [message] => test [g-recaptcha-response] => )
So... as I was saying.. you just need to check in your PHP code that the variable
$_POST['g-recaptcha-response'] is not empty using an if !empty
and based on that... process the request or not.
--
Best regards,
Jordane-
-
-
-
Do you know how to search the internet? because well... I gave you all the indications!
Make an IF
use !empty ..
Anyway :if (!empty($_POST['g-recaptcha-response'])) { die('MF001'); // or any other code... I haven't looked at what they serve in your case. } if (!count($addresses[0])) { die('MF001'); } -
-
-
Pardon.. it's an empty that should be used and not a !empty
if (empty($_POST['g-recaptcha-response'])) { die('MF001'); // or any other code... I haven't looked at what they are for in your case. }