Skip to content

Instantly share code, notes, and snippets.

@Hexodus
Created March 12, 2016 13:15
Show Gist options
  • Save Hexodus/33144079415ae720fcec to your computer and use it in GitHub Desktop.
Save Hexodus/33144079415ae720fcec to your computer and use it in GitHub Desktop.
Google ReCaptcha secure token generation using slushie class from: https://github.com/slushie/recaptcha-secure-token/blob/master/lib/ReCaptchaToken.php Secure token makes it possible to use ReCaptcha for testing on localhost.
<?PHP
use ReCaptchaSecureToken\ReCaptchaToken as ReCaptchaToken;
require_once("ReCaptchaToken.php");
//Generate recaptcha token
$recaptcha_config = [
'site_key' => 'your-site-key',
'site_secret' => 'your-site-secret-key'
];
$recaptcha_token = new ReCaptchaToken($recaptcha_config);
$recaptcha_session_id = uniqid('recaptcha');
$recaptcha_secure_token = $recaptcha_token->secureToken($recaptcha_session_id);
//template file with the recaptcha
<div class="g-recaptcha" data-sitekey="<?= $recaptcha_config['site_key'] ?>"
data-stoken="<?= $recaptcha_secure_token ?>" ></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment