1//using curl recaptcha v3 (sajo sunny)
2//add elements using html
3(don't add elements to dom using script)
4
5
6https://code.tutsplus.com/tutorials/example-of-how-to-add-google-recaptcha-v3-to-a-php-form--cms-33752
1<script>
2 grecaptcha.ready(function() {
3 grecaptcha.execute('SITEKEY', {action: 'submit'}).then(function(token) {
4 document.getElementById("token").value = token;
5 });
6 });
7 </script>
1
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <script src="https://www.google.com/recaptcha/api.js?render=SITEKEY"></script>
7 <meta name="viewport" content="width=device-width, initial-scale=1.0">
8 <title>Document</title>
9</head>
10<body>
11 <form method="post" action="">
12 <input type="hidden" name="token" id="token">
13 <button type="submit" name="submit">Send</button>
14 </form>
15 <script>
16 grecaptcha.ready(function() {
17 grecaptcha.execute('SITEKEY', {action: 'submit'}).then(function(token) {
18 document.getElementById("token").value = token;
19 });
20 });
21 </script>
22</body>
23</html>
24
25
26 if(isset($_POST['submit'])){
27 $request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRETKEY&response=" . $_POST['token']);
28 $request = json_decode($request);
29 if($request->success == true){
30 if($request->score >= 0.6){
31 // Do something
32 }else{
33 echo "error";
34 }
35 }
36 }
37
1What is reCAPTCHA? reCAPTCHA protects your website from fraud and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive challenges to keep malicious software from engaging in abusive activities on your website.
1This package is abandoned. The sad fact is that I don't have time to maintain
2this package, so the release of Laravel 6 is as good as any to make a clean
3break.
4
5Alternative : https://github.com/biscolab/laravel-recaptcha