markdown Recaptcha v3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Recaptcha v3相关的知识,希望对你有一定的参考价值。

# Recaptcha v3
https://www.google.com/recaptcha/intro/v3.html

## PHP
### Define Keys
```php
define( 'SITE_KEY', '' );
define( 'SECRET_KEY', '' );
```

### Create Function
```php
function getCaptcha( $secret_key ) {
	$response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=${SECRET_KEY}&response=${$secret_key}" );
	$return = json_decode( $response );
	return $return;
}

$captcha = getCaptcha($_POST['g-recaptcha-response']);
```

## HTML
```html
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
```

## JavaScript
```js
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo SITE_KEY; ?>"></script>
<script>
grecaptcha.ready(function() {
	grecaptcha.execute('<?php echo SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
		document.querySelector('#g-recaptcha-response').value = token;
	});
});
</script>
```

以上是关于markdown Recaptcha v3的主要内容,如果未能解决你的问题,请参考以下文章

Google reCaptcha v3 与 google reCaptcha Enterprise

如何解决 Google v3 reCaptcha 超时?

php 谷歌reCAPTCHA v3

谷歌 reCAPTCHA v3 左下角

密钥如何与 reCAPTCHA v3 Enterprise 配合使用?

使用 ng-recaptcha 将 Google reCaptcha v3 集成到 Angular 应用程序中