-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# 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": "1.0" | ||
|
||
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 | ||
} | ||
|
||
## 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'); | ||
|
||
|
||
## Full example | ||
|
||
Here is an example : | ||
|
||
<?php | ||
require 'vendor/autoload.php'; | ||
use Phelium\Component\reCAPTCHA; | ||
|
||
$reCAPTCHA = new reCAPTCHA('your site key', 'your secret key'); | ||
?> | ||
|
||
<html> | ||
<head> | ||
<title>reCAPTCHA example</title> | ||
<?php echo $reCAPTCHA->getScript(); ?> | ||
</head> | ||
|
||
<body> | ||
|
||
<?php | ||
if (isset($_POST['name'])) | ||
{ | ||
var_dump($_POST); | ||
|
||
if ($reCAPTCHA->isValid($_POST['g-recaptcha-response'])) | ||
{ | ||
echo '<br>-- Captcha OK ! --<br>'; | ||
} | ||
} | ||
?> | ||
|
||
<form action="#" method="POST"> | ||
<input type="text" name="name" placeholder="name"> | ||
|
||
<?php echo $reCAPTCHA->getHtml(); ?> | ||
|
||
<input type="submit"> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "phelium/recaptcha", | ||
"description": "reCAPTCHA v2 class", | ||
"keywords": ["recaptcha", "captcha", "google"], | ||
"homepage": "https://github.com/shevabam/recaptcha", | ||
"authors": [ | ||
{ | ||
"name": "ShevAbam" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/shevabam/recaptcha/issues", | ||
"source": "https://github.com/shevabam/recaptcha/tree/master" | ||
}, | ||
"license": "GNU GPL 2.0", | ||
"version": "1.0", | ||
"require": { | ||
"php": ">=5.3.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Phelium\\Component\\": "src" | ||
} | ||
} | ||
} |
Oops, something went wrong.