Firebase Project : Firebase 콘솔 에 액세스하고 새 프로젝트를 작성하고 API 키를 얻습니다.
PHP 환경 구성 : PHP 및 관련 확장이 로컬 또는 서버 환경에 올바르게 설치되어 있는지 확인하십시오.
<?php
require_once('path/to/firebase/autoload.php');
use Kreait\Firebase\Factory;
// 초기화 Firebase 예
$firebase = (new Factory)
->withServiceAccount('path/to/firebase/serviceAccountKey.json')
->create();
API 키를 설정 해야하는 경우 구성을 더 확장 할 수 있습니다.
<?php
$firebase = (new Factory)
->withServiceAccount('path/to/firebase/serviceAccountKey.json')
->withApiKey('your-api-key')
->create();
먼저 Firebase 콘솔에서 Recaptcha를 활성화하고 해당 사이트 키를 얻습니다. 다음으로 백엔드에서 확인 코드 유효성 검사기를 인스턴스화합니다.
<?php
$recaptcha = $firebase->getAuth()->getRecaptchaVerifier([
'siteKey' => 'your-site-key',
]);
<html>
<body>
<form>
<!-- 추가 reCAPTCHA 검증 영역 -->
<div id="recaptcha-container"></div>
<button type="submit">Submit</button>
</form>
<!-- 소개 reCAPTCHA ~의 JavaScript 스크립트 -->
<script src="https://www.google.com/recaptcha/api.js?render=explicit"></script>
grecaptcha.ready(function() {
grecaptcha.execute('your-site-key', {action: 'homepage'}).then(function(token) {
document.getElementById('recaptcha-token').value = token;
});
});
</script>