Firebase Project: Log in to the Firebase Console, create a new project, and obtain your API key.
PHP Development Environment: Ensure that PHP is installed and properly configured on your server or local machine.
<?php
require_once('path/to/firebase/autoload.php');
use Kreait\Firebase\Factory;
// Initialize Firebase
$firebase = (new Factory)
->withServiceAccount('path/to/firebase/serviceAccountKey.json')
->create();
If needed, configure the API key as well:
<?php
$firebase = (new Factory)
->withServiceAccount('path/to/firebase/serviceAccountKey.json')
->withApiKey('your-api-key')
->create();
Enable reCAPTCHA in the Firebase console and get your site key. Then, initialize the verifier on the backend:
<?php
$recaptcha = $firebase->getAuth()->getRecaptchaVerifier([
'siteKey' => 'your-site-key',
]);
<html>
<body>
<form>
<!-- Add reCAPTCHA container -->
<div id="recaptcha-container"></div>
<button type="submit">Submit</button>
</form>
<!-- Load 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>