-
Notifications
You must be signed in to change notification settings - Fork 2
/
captcha.php
32 lines (23 loc) · 892 Bytes
/
captcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* Basic PHP code to use Google reCAPTCHA v2 with YOURLS.
* Code borrowed from: https://github.com/armujahid/Admin-reCaptcha/blob/master/captcha.php
*/
require_once "autoload.php";
// Register API keys at https://www.google.com/recaptcha/admin
$siteKey = yourls_get_option( 'adminnorecaptcha_pub_key' );
$secret = yourls_get_option( 'adminnorecaptcha_priv_key' );
// More languages: https://developers.google.com/recaptcha/docs/language
$lang = "en";
// The response from reCAPTCHA
$resp = null;
// The error code from reCAPTCHA, if any
$error = null;
if ($siteKey == "" || $secret == "") {
die("To use reCAPTCHA you must get an API key.");
}
elseif (isset($_POST['g-recaptcha-response'])) {
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
}
?>