mashkin/recaptcha-serviceprovider
最新稳定版本:v2.0
Composer 安装命令:
composer require mashkin/recaptcha-serviceprovider
包简介
Provides Google's ReCaptcha API as a Silex ServiceProvider
README 文档
README
Silex ServiceProvider integrating Google's ReCaptcha service
Installation
Through Composer
Add this package to your composer.json file and composer update
{
...
"require": {
...
"mashkin/recaptcha-serviceprovider": "dev-master"
}
}
Or simply do composer require "mashkin/recaptcha-serviceprovider" "dev-master".
Usage
As ServiceProvider
Register the RecaptchaServiceProvider and provide your configuration:
$app->register(new Mashkin\RecaptchaServiceProvider(), array(
'recaptcha.sitekey' => 'YOUR_SITE_KEY',
'recaptcha.secret' => 'YOUR_SITE_SECRET'
));
// Optional:
// Set language parameter that will be passed to ReCaptcha (default: en)
$app['recaptcha.language'] = 'de';
// Set stream context for API call (file_get_contents()) (default: null)
$app['recaptcha.streamContext'] = ...;
On Application::boot(), $app['recaptcha.language'] will be set to $app['locale'].
The ServiceProvider provides an instance of Mashkin\Recaptcha as $app['recaptcha'].
Use it as described below.
Standalone
// Do your configuration
// Required:
$siteKey = 'YOUR_SITE_KEY';
$siteSecret = 'YOUR_SITE_SECRET';
// Optional:
$language = 'de';
$streamContext = ...; // Passed to file_get_contents()
// Create an instance of Mashkin\Recaptcha
$recaptcha = new Recaptcha($siteKey, $siteSecret, $language, $streamContext)
// Get ReCpatcha widget code
// Get target element
echo $recaptcha->getHtmlElement();
// Get JavaScript
echo $recaptcha->getHtmlScript();
// Verify Captcha response
if (isset($_POST['g-recaptcha-response'])) {
$result = $recaptcha->checkResponse($_POST['g-recaptcha-response']);
if ($result['success']) {
echo "Success";
} else {
echo "Some errors occured: ";
echo implode(', ', $result['error-codes']);
die();
}
} else {
die('No captcha response submitted');
}
统计信息
- 总下载量: 409
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-04