Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shevabam/recaptcha
Google reCAPTCHA v2 PHP class
https://github.com/shevabam/recaptcha
google-recaptcha recaptcha recaptchav2
Last synced: about 2 months ago
JSON representation
Google reCAPTCHA v2 PHP class
- Host: GitHub
- URL: https://github.com/shevabam/recaptcha
- Owner: shevabam
- License: gpl-2.0
- Created: 2015-01-13T13:44:50.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-13T13:33:26.000Z (over 6 years ago)
- Last Synced: 2024-05-13T05:09:16.409Z (8 months ago)
- Topics: google-recaptcha, recaptcha, recaptchav2
- Language: PHP
- Size: 20.5 KB
- Stars: 42
- Watchers: 9
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reCAPTCHA
- [Installation](#installation)
- [Initialization](#initialization)
- [Usage](#usage)
- [Customization](#customization)
- [Theme](#theme)
- [Language](#language)
- [Type](#type)
- [Full example](#full-example)## Installation
With Composer, add this line to your *require* section :
"phelium/recaptcha": "dev-master"
Then run `composer update`.
## Initilization
require 'vendor/autoload.php';
use Phelium\Component\reCAPTCHA;
To initialize reCAPTCHA, you must provide your site key and your secret key.
There is two possible ways :$reCAPTCHA = new reCAPTCHA('your site key', 'your secret key');
or
$reCAPTCHA = new reCAPTCHA();
$reCAPTCHA->setSiteKey('your site key');
$reCAPTCHA->setSecretKey('your secret key');## Usage
To generate the *script* tag, use :
$reCAPTCHA->getScript();
To generate the HTML block, use in your form :
$reCAPTCHA->getHtml();
Checking the server side, in your form validation script :
if ($reCAPTCHA->isValid($_POST['g-recaptcha-response']))
{
// do whatever you want, the captcha is valid
}
else
{
// Show errors
var_dump($reCAPTCHA->getErrorCodes());
}## Customization
### Theme
Several themes are available : light (default) or dark.
$reCAPTCHA->setTheme('dark');### Language
You can change the language of reCAPTCHA. Check [https://developers.google.com/recaptcha/docs/language](https://developers.google.com/recaptcha/docs/language) for more information.
By default, the language is automatically detected.$reCAPTCHA->setLanguage('it');
### Type
Several types are available : image (default) or audio.
$reCAPTCHA->setType('audio');
### Size
Two sizes are available : normal (default) or compact.
$reCAPTCHA->setType('compact');
## Full example
Here is an example :
reCAPTCHA example
getScript(); ?>
isValid($_POST['g-recaptcha-response']))
{
echo '
-- Captcha OK ! --
';
}
}
?>
getHtml(); ?>