D
D
Dmitry23072019-10-29 17:38:27
PHP
Dmitry2307, 2019-10-29 17:38:27

Why does it display errors when displaying captcha from google?

Throws an error on page load: The source list for Content Security Policy directive 'script-src' contains an invalid source: ''strict-dynamic''. It will be ignored.
I can not understand the reason, tell me.

<?php
require 'templates/header.php';

define('SITE_KEY', '..........................................');
define('SECRET_KEY', ..........................................');
if($_POST){
    function getCaptcha($SecretKey) {
        $Response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".SECRET_KEY."&response={$SecretKey}");
        $Return = json_decode($Response);
        return $Return;
    }
    $Return = getCaptcha($_POST['g-recaptcha-response']);
    var_dump($Return);
    if($Return->success == true && $Return->score > 0.5){
        echo "Проверка пройдена. Сообщение отправлено!";
    } else {
        echo "You are Robot";
    }
}
?>


<section class="registration main">
  <div class="row">
    <div class="col-12 reg__ramka">
      <div class="row">
        <div class="col-6">

        </div>
        <div class="col-6">
          <h3>Регистрация</h3>
          <form method="post" id="form_reg" action="/">
            
            <p id="reg_message"></p>
            <div id="form_registration">
              <ul class="form__reg_ul">
                <li>
                  <label class="form__reg_label">Телефон:</label>
                  <span class="reg_star">*</span>
                  <input type="text" name="reg_phone" id="reg_phone">
                </li>
                <li>
                  <label class="form__reg_label">e-mail:</label>
                  <span class="reg_star">*</span>
                  <input type="text" name="reg_email" id="reg_email">
                </li>
                <li>
                  <label class="form__reg_label">Пароль:</label>
                  <span class="reg_star">*</span>
                  <input type="text" name="reg_pass" id="reg_pass">
                  <span id="genpass">cгенерировать</span>
                </li>
                <li>
                  <label class="form__reg_label">Имя:</label>
                  <span class="reg_star">*</span>
                  <input type="text" name="reg_name" id="reg_name">
                </li>
                <li>
                  <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">

<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) {
                // console.log(token);
                document.getElementById('g-recaptcha-response').value=token;
            });
        });
  </script>
                </li>
              </ul>
              <div class="form__reg_button">
                <button type="submit" name="reg_submit" id="reg_submit">Регистрация <i class="fa fa-chevron-right" aria-hidden="true"></i></button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>

<?php
require 'templates/footer.php';
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petr Sh, 2019-10-30
@Dmitry2307

https://developer.mozilla.org/en-US/docs/Web/HTTP/...
We look at the table and see that strict-dynamic is not supported by all browsers.
If these rules are on the side of Google, then you cannot do anything.

advice
используйте нормальный браузер

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question