承接 phpdevsr/recaptcha-codeigniter4 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

phpdevsr/recaptcha-codeigniter4

Composer 安装命令:

composer require phpdevsr/recaptcha-codeigniter4

包简介

Free to Use Library reCAPTCHA v2 for Codeigniter 4

README 文档

README

PHPUnit PHPStan Coverage Status Downloads GitHub release (latest by date) GitHub stars GitHub license

reCAPTCHA Codeigniter 4

Free to Use Library reCAPTCHA v2 for Codeigniter 4.

What is reCAPTCHA?

reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis engine to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the reCAPTCHA challenge without having to solve a CAPTCHA (See blog for more details). reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.

See the details.

Sign up for an API key pair

To use reCAPTCHA, you need to sign up for an API key pair for your site. The key pair consists of a site key and secret. The site key is used to display the widget on your site. The secret authorizes communication between your application backend and the reCAPTCHA server to verify the user's response. The secret needs to be kept safe for security purposes.

Installation

install with composer

$ composer require phpdevsr/recaptcha-codeigniter4
$ php spark config:publish

Usage

Since v2.1.0, environment config can be use for multiple config with .env

recaptcha.recaptchaSiteKey
recaptcha.recaptchaSecretKey
recaptcha.recaptchaLang

Initialization

<?php

require 'vendor/autoload.php';

use Config\Recaptcha as RecaptchaConfig;
use PHPDevsr\Recaptcha\Recaptcha;

class Example
{
    /**
     * Config Recaptcha
     * 
     * @var RecaptchaConfig $config
     */
    protected RecaptchaConfig $config;

    /**
     * Recaptcha
     * 
     * @var Recaptcha $recaptcha
     */
    protected Recaptcha $recaptcha;

    public function __construct()
    {
        // Set Config
        $this->config = new RecaptchaConfig();

        $this->recaptcha = new Recaptcha($this->config);
    }
}

Since v2.0.0, you can using helper

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index(): string
    {
        helper('recaptcha');

        $data = [
            'scriptTag' => getScriptTag(),
            'widgetTag' => getWidget(),
        ];

        $captcha = $this->request->getPost('g-recaptcha-response');
        $response = verifyResponse($captcha);

        if (isset($response['success']) and $response['success'] === true) {
            echo "You got it!";
        }

        return view('welcome_message', $data);
    }
}

or directly use service

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index(): string
    {
        $recaptcha = service('recaptcha');

        $data = [
            'scriptTag' => $recaptcha->getScriptTag(),
            'widgetTag' => $recaptcha->getWidget(),
        ];

        $captcha = $this->request->getPost('g-recaptcha-response');
        $response = $recaptcha->verifyResponse($captcha);

        if (isset($response['success']) and $response['success'] === true) {
            echo "You got it!";
        }

        return view('welcome_message', $data);
    }
}

Render reCAPTCHA Widget

  • Default
echo $this->recaptcha->getWidget();

// Output
<div class="g-recaptcha" data-sitekey="xxxxx" data-theme="light" data-type="image" data-size="normal" loading="lazy"></div>
  • Theme
echo $this->recaptcha->getWidget(array('data-theme' => 'dark'));

// Output
<div class="g-recaptcha" data-sitekey="xxxxx" data-theme="dark" data-type="image" data-size="normal" loading="lazy"></div>
  • Type
echo $this->recaptcha->getWidget(array('data-theme' => 'dark', 'data-type' => 'audio'));

// Output
<div class="g-recaptcha" data-sitekey="xxxxx" data-theme="dark" data-type="audio" data-size="normal" loading="lazy"></div>

Render Script Tag

  • Default
echo $this->recaptcha->getScriptTag();

// Output
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=onload&hl=en" defer></script>
  • Render
echo $this->recaptcha->getScriptTag(array('render' => 'explicit'));

// Output
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=explicit&hl=en" defer></script>
  • Language
echo $this->recaptcha->getScriptTag(array('hl' => 'id'));

// Output
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=onload
&hl=id" defer></script>

Verify Response

Calls the reCAPTCHA siteverify API to verify whether the user passes g-recaptcha-response POST parameter.

$captcha = $this->request->getPost('g-recaptcha-response');
$response = $this->recaptcha->verifyResponse($captcha);

if (isset($response['success']) and $response['success'] === true) {
    echo "You got it!";
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contrib

We does accept and encourage contributions from the community in any shape. It doesn't matter whether you can code, write documentation, or help find bugs, all contributions are welcome.

Made with contrib.rocks.

phpdevsr/recaptcha-codeigniter4 适用场景与选型建议

phpdevsr/recaptcha-codeigniter4 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.14k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2023 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「recaptcha」 「codeigniter」 「codeigniter4」 「google-recaptcha」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 phpdevsr/recaptcha-codeigniter4 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phpdevsr/recaptcha-codeigniter4 我们能提供哪些服务?
定制开发 / 二次开发

基于 phpdevsr/recaptcha-codeigniter4 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-01