Recaptcha V2 with Formtoemailpro - recaptcha

Has anyone edited formtoemailpro to use Recaptcha v2? This is the formtoemailpro developer version which gives you a PHP script: (https://formtoemail.com/developer_pricing.php)
I tried changing
// Check reCAPTCHA
if($reCAPTCHA)
{
require_once('recaptchalib.php');
$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_REQUEST["recaptcha_challenge_field"],$_REQUEST["recaptcha_response_field"]);
if(!$resp->is_valid)
{
$errors[] = "The reCAPTCHA wasn't entered correctly. Go back and try it again (reCAPTCHA said: " . $resp->error . ")";
}
unset($_REQUEST["recaptcha_challenge_field"]);
unset($_REQUEST["recaptcha_response_field"]);
}
to
// Check reCAPTCHA
if($reCAPTCHA)
{
//require_once('recaptchalib.php');
//$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_REQUEST["recaptcha_challenge_field"],$_REQUEST["recaptcha_response_field"]);
$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_REQUEST["g-recaptcha-response"]);
if(!$resp->is_valid)
{
$errors[] = "The reCAPTCHA wasn't entered correctly. Go back and try it again (reCAPTCHA said: " . $resp->error . ")";
}
unset($_REQUEST["g-recaptcha-response"]);
}
But got errors.
This page isn’t working
webeg.uk is currently unable to handle this request.
Test is at http://webeg.uk/aaq/
Can anyone point me to the right direction?

I think I have a solution, please feel free to test and critique:
In place of the existing reCaptcha lines in formtoemailpro as above, enter the following:
// Check reCAPTCHA
if($reCAPTCHA)
{
if(isset($_REQUEST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$privatekey&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==true)
{
unset($_REQUEST['g-recaptcha-response']);
}
}
Thank you

Related

How to get Google reCAPTCHA v2 data-sitekey?

I have this code for my Google Chrome extension which solves reCAPTCHA automatically.
"use strict"
var sid = setInterval(function () {
if (window.location.href.match(/https:\/\/www.google.com\/recaptcha\/api\d\/anchor/) && $("#recaptcha-anchor div.recaptcha-checkbox-checkmark").length
&& $("#recaptcha-anchor div.recaptcha-checkbox-checkmark").is(':visible') && isScrolledIntoView($("#recaptcha-anchor div.recaptcha-checkbox-checkmark").get(0)))
{
var execute = true;
if (sessionStorage.getItem('accesstime'))
{
if (new Date().getTime() - sessionStorage.getItem('accesstime') < 7000)
{
execute = false;
}
}
if (execute)
{
$("#recaptcha-anchor div.recaptcha-checkbox-checkmark").click();
sessionStorage.setItem('accesstime', new Date().getTime());
}
clearInterval(sid);
}
}, 500);
My question is...
From the above code. How do I get the data-sitekey and page url?
I know this is old, but for people in same situation:
Use your account of Google(Gmail)
go to this link https://www.google.com/recaptcha/intro/v3beta.html
- use the button Myrecaptcha
- register a new site
- give a label "my site label"
- Choose the type of reCAPTCHA
- enter the domain for you want use the captcha
- check the Accept the reCAPTCHA Terms of Service.
- check or not the send alerts to owners
- Click "register"
That´s all when finish you will see intructions and your data-sitekey.

Google reCAPTCHA working on Local but not on my server

I have a form which requires a google reCAPTCH to be ticked. It is working perfectly on Local but does not work when I put it on the development server. I have replaced the registered keys to the ones appointed to me by Google.
It keeps outputting the error message.
The method in my form is post.
I do not understand why it doesn't work. Can someone please help me?
Here is my code:
$secretKey = "#######";
$captcha = $_POST['g-recaptcha-response'];
$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) {
$throwErrorMessage = "You are a robot! ";
$throwError = 1;
$isvalid = False;
};
What version of ReCAPTCHA are you using? The docs on Google website here are pretty different than your code. In particular, you use the function file_get_contents while the documentation uses recaptcha_check_answer like in this example:
<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."."(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
Can you post the error message?

Why the else statement not working here?

The following code can't get correct response under the else statment:
function ajax_response(){
if(is_user_logged_in() && check_key() ){
$result = $do_something;
if($result){
ajax_response_string(1,'success!');
}else{
ajax_response_string(-1,'there is a problem, please try again!');
}
}else{
ajax_response_string(-1,'you must login first.');
}
}
When I log-out and try to click the link that trigger this ajax function, I got a response of "undefined", it is supposed to be "you must login first". Where I've gone wrong?
I just figured it out-- it's not the else statement, it's the ajax response url not working for logged out users. So, my question is not valid anymore. Please close it if necessary.
You have a syntax error at line $result= //do something because this line is not terminated. Try this:
function ajax_response()
{
if(is_user_logged_in() && check_key() )
{
$result = doSomething; //error was here as there was no line terminator (;) present.
if($result)
{
ajax_response_string(1,'success!');
}
else
{
ajax_response_string(-1,'there is a problem, please try again!');
}
}
else
{
ajax_response_string(-1,'you must login first.');
}
}

Catching error with Usermanager.getUser() in Google Apps Script

I am working withing Google Spreadsheet creating a script file that has to deal with obtaining user information on my Google Apps Domain. I have admin rights and the Provisioning API is enabled. In my code, I am trying to catch the error when looking up a specific user on a Google Apps Domain (user not found) and instead display a message and continuing on with the rest of the program. The try-catch statement I have here works when there is no error on the user. However, when there is an error on retrieving the user, I get the error: "Unexpected exception upon serializing continuation". Here is my code:
function testOfDomainAccess() {
var i=0;
var anArray= ["johhn.smith", "susan.que]; //john smith misspelled
var user;
for (i=0; i < anArray.length; ++i)
{
Logger.log("\nThe current user being processed is " + anArray[i]);
try
{
user = UserManager.getUser (anArray [i]);
}
catch (error)
{
Browser.msgBox("Error: " + error.name + "\n Check your spreadsheet for misspellings of " + anArray[i] + " and We will continue to the next user.");
user = null;
}
if (user != null) {
//Perform tasks
}
else
Logger.log("User not found in domain. Moving on the next item in the array.");
}
If anyone can help with this problem I would greatly appreciate it. I am new to Google Apps Script and Provisioning API. Thanks!
It looks like the same bug reported at http://code.google.com/p/google-apps-script-issues/issues/detail?id=980.
The workaround is to replace the Browser.msgBox() call with Logger.log() and your script should run as expected.

Same Ajax is not working in IE more than one time

i my webpage when the user click forgot password button i ask email , Securitykey etc.. when the user click the sendmail button i send the email,securitykey, etc to a ajax function named 'sendmail(par1,par2,par3)' [Code is below]. The user provide Existing mailid , securitykey... , rtstr[1] is set to 1 [one] . So the 'Mail send successfully' was displayed . But if the user again enter the info [without refreshing the page]and click sendmail button, it didn't work in IE. But it works perfectly in Firefox.
var xmlhttp1;
xmlhttp1 = GetXmlHttpObject();
function sendmail(Mailforpwd, Secquestion, Secanswer) {
if (xmlhttp1 == null) {
alert("Browser does not support HTTP Request");
return;
}
var url = "SendEmail.php";
url = url + "?Email=" + Mailforpwd;
url = url + "&Squestion=" + Secquestion;
url = url + "&Sanswer=" + Secanswer;
xmlhttp1.onreadystatechange = stateChanged;
xmlhttp1.open("GET", url, true);
xmlhttp1.send(null);
function stateChanged() {
if (xmlhttp1.readyState == 4) {
var Result = xmlhttp1.responseText;
rtstr = Result.split('#');
//alert(xmlhttp1.responseText);
//alert(rtstr[0]);
//alert(rtstr[0]);
if (rtstr[0] == 1) {
document.getElementById("Errorcredentials").innerHTML = "Mail send successfully";
}
else if (rtstr[1] == 0) {
//alert(document.getElementById("Errorcredentials").innerHTML);
document.getElementById("Errorcredentials").innerHTML = "Please provide Exist information";
}
else {
document.getElementById("Errorcredentials").innerHTML = "There is a problem in sending mail, please try after sometime";
}
}
}
}
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
Here my problem is at second time the function stateChanged() was not called , if i put a alert in this function , first time it display alert box , But next time it won't. This is my problem . The sendMail.php was called eachtime .
Whenever I have this problem it is because IE caches your AJAX request. The best way to avoid this is to append a random number as a key in your query string each time.
url = url + "&rand=" + Math.random();
Or, better, since your AJAX request appears to be causing some action to happen server-side, why don't you use HTTP POST instead of GET?
xmlhttp1.open("POST", url, true);
This is a caching problem. Append current date time to your url to make it unique.
url = url + "&rand=" + (new Date());
just swap these lines in your code.
xmlhttp1.onreadystatechange = stateChanged;
xmlhttp1.open("GET", url, true);
after fixing it looks like
xmlhttp1.open("GET", url, true);
xmlhttp1.onreadystatechange = stateChanged;
thats it!!
skypeid: satnam.khanna

Resources