Andrew7v Posted July 15, 2017 Share Posted July 15, 2017 Hi, I have a basic php form that has some if(empty) code that check to make sure the fields are filled out and then if ok, it processes and emails me the data. It's all on the same php page. But I'm having a hard time trying to figure out how to get Google Recaptcha to work... Can someone please help me figure this out? Thanks *Attached is my form with all the important parts, and asterisks where my google captcha site keys would be... contactform.php Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 15, 2017 Share Posted July 15, 2017 (edited) Read the forum rules. When you expect help with a problem, you need to provide concrete information: symptoms, error messages, your attempts at solving them etc. Simply posting a script and telling us that there's something wrong with it doesn't work. We cannot read your mind, we're not sitting in front of your screen, and we aren't going to play guess-what-my-problem-is with you. When you post code, use code tags. Attaching it as a file is very annoying, because it cannot be accesses by guests, it cannot be searched, it cannot be indexed by Google, and it doesn't have syntax highlighting. Edited July 15, 2017 by Jacques1 Quote Link to comment Share on other sites More sharing options...
Gandalf64 Posted July 15, 2017 Share Posted July 15, 2017 (edited) I'll help you with what I thought was the tricky part of Google ReCaptcha (How I resolved it was not only going to Google, but searching the internet. You'll be surprised how many before you have had the same issue), for I think you can get the rest by going to Google themselves. When the user clicks on the I'm human checkbox this is how I would set up the response. if (isset($submit) && $submit === 'submit') { /* The Following to get response back from Google Recaptha */ $url = "https://www.google.com/recaptcha/api/siteverify"; $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL); $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer); $recaptcha_data = json_decode($response); /* The actual check of the recaptcha */ if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) { /* Example data gather from the form (actually my contact form) */ $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS); /* The following would be your way of sending the email */ $send = new Email($data); // This is my way, by sending it to a class: } else { $errMessage = "You're not a human!"; } } Edited July 15, 2017 by Gandalf64 2 Quote Link to comment Share on other sites More sharing options...
Andrew7v Posted July 16, 2017 Author Share Posted July 16, 2017 Great, thank you very much Gandalf64... I will try that out and see if i can work it out. Really appreciate it! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 16, 2017 Share Posted July 16, 2017 The code above has its own problems (like the reliance on the potentially insecure allow_url_fopen setting and the random and incorrect use of HTML-escaping). So instead of continuously relying on others to spoonfeed you (half-)working code, you should take the chance to grow up as a programmer and learn how to solve problems yourself. Yes, that's more work than the usual “My code is broken, please fix it for me!”, but it's worth it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.