You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Copy the config.php.dist file to config.php and update it with your keys
$config = include DIR . '/config.php';
if ($siteKey == '' && is_readable(DIR . '/root/www/site-root/wwww/config.php')) {
$siteKey = $config['v3']['site'];
$secret = $config['v3']['secret'];
}
// reCAPTCHA supports 40+ languages listed here: https://developers.google.com/recaptcha/docs/language
$lang = 'en';
$lang = 'ru';
Issue description
Google Recaptcha v3 gives invalid response.
Installed by compressor command - composer require google/recaptcha "^1.2"
Please to solve the problem.
In controler file plase code:
`require DIR . '/appengine-https.php';
//reCAPTCHA PHP client library
require_once '/root/www/site-root/vendor/google/recaptcha/src/autoload.php';
//Secret key
$siteKey = 'My key';
$secret = 'My key';
// Copy the config.php.dist file to config.php and update it with your keys
$config = include DIR . '/config.php';
if ($siteKey == '' && is_readable(DIR . '/root/www/site-root/wwww/config.php')) {
$siteKey = $config['v3']['site'];
$secret = $config['v3']['secret'];
}
// reCAPTCHA supports 40+ languages listed here: https://developers.google.com/recaptcha/docs/language
$lang = 'en';
$lang = 'ru';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha
->setExpectedHostname('my_site.com')
->setExpectedAction('homepage')
->setScoreThreshold(0.5)
->verify('token', $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
//$this->error_msg = 'ReCaptcha field is required.';
}
if ($resp->getScore() < 0.5) {
header('Location: success.htm');
exit();
//$recaptchaErrors = $response->getErrorCodes();
} else {
// otherwise, let the spammer think that they got their message through
//header('Location: success.htm');
//exit();
}`
In .tpl file plased code:
`
<title>Google reCAPTCHA</title>
<script src='https://www.google.com/recaptcha/api.js?render=site_key' ></script>
`
print_r($recaptcha); ---->
ReCaptcha\ReCaptcha Object
(
[secret:ReCaptcha\ReCaptcha:private] => bhfbj4bfi48y8fhu9023ijr4fnhu5fbnjf5eofj5nf5inf5in5
[requestMethod:ReCaptcha\ReCaptcha:private] => ReCaptcha\RequestMethod\Post Object
(
[siteVerifyUrl:ReCaptcha\RequestMethod\Post:private] => https://www.google.com/recaptcha/api/siteverify
)
print_r($resp); ----->
ReCaptcha\Response Object
(
[success:ReCaptcha\Response:private] =>
[errorCodes:ReCaptcha\Response:private] => Array
(
[0] => invalid-input-response
[1] => hostname-mismatch
[2] => action-mismatch
[3] => score-threshold-not-met
)
Environment
LinuxLinux
google/recaptcha
version: 1.2Reproducing the issue
On demand please.
The text was updated successfully, but these errors were encountered: