phelium/recaptcha 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phelium/recaptcha

最新稳定版本:1.0.8

Composer 安装命令:

composer require phelium/recaptcha

包简介

reCAPTCHA v2 class

README 文档

README

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 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 :

<?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> 

统计信息

  • 总下载量: 86.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 44
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 43
  • Watchers: 6
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固