Download the PHP package petalbranch/icon-captcha without Composer

On this page you can find all versions of the php package petalbranch/icon-captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package icon-captcha

IconCaptcha

👉 中文 | English

这是一个轻量级、安全且易于集成的 PHP 图标点选验证码库。用户需要按照提示图标的顺序,在图片中依次点击对应的图标来完成验证。

✨ 特性

👀 示意图

以下图片为前端的验证码展示效果参考,具体需要自行实现。

📦 安装

⚠️ 安全警告 (Security Warning)

icon_captcha_generate() 函数返回的数组中包含 answer 字段(正确坐标数据)。

绝对禁止 将 answer 字段直接返回给前端(浏览器/客户端)。 你 必须 将 answer 数据存储在服务端的 Session、Redis 或数据库中,验证时再取出比对。

快速开始

  1. 生成验证码

在你的控制器(Controller)中生成验证码数据:

  1. 前端展示说明 (客户端) 前端在接收到数据后,需要注意 主图 和 提示图标 的 Base64 前缀处理方式不同。
    • 主图 (image):可能是 WebP 或 PNG,需根据返回的 mime 字段动态拼接。
    • 提示图标 (icons):为了保持透明背景,统一固定为 PNG 格式。

HTML/JS 拼接示例:

  1. 验证验证码 (服务端)

前端收集用户的点击坐标后,提交到验证接口:

🔐 安全增强:点击位置加密

为了防止恶意用户直接通过抓包工具篡改或伪造点击坐标,建议在前端对点击位置进行加密,后端解密后再传入 icon_captcha_verify 进行校验。

流程:

  1. 前端:用户点击 -> 获得坐标数组 -> JSON序列化 -> 加密 (AES/RSA) -> 发送密文。
  2. 后端:接收密文 -> 解密 -> 获得坐标数组 -> 调用 icon_captcha_verify。

    具体代码示例请参考项目 examples 或根据自身业务逻辑实现。

    • 前端加密 (示例)

假设你使用 crypto-js 或其他库对坐标数组进行 AES 加密:

在 PHP 控制器中,先解密数据,还原成数组格式,再传给验证函数:

⚙️ 参数配置

参数 类型 默认值 说明
$width int 320 验证码图片宽度
$height int 200 验证码图片高度
$length int 4 需要用户点击的正确图标数量
$decoyIconCount int 2 干扰图标数量(不计入答案)
$iconSet IconSetInterface null 自定义字体集实例
$backgroundImageFolder string null 自定义背景图片文件夹路径
$useWebp bool true 优先使用 WebP 格式(体积更小),若不支持自动回退到 PNG

🎨 高级用法

自定义背景图

默认情况下,库会生成随库自带的随机背景。如果你想使用随机背景图片:

自定义图标字体 默认的 IconSet 是配合内置的 FontAwesome 字体使用的。如果你想使用自己的 .ttf 字体文件,你需要创建一个新类来实现 IconSetInterface 接口,并定义该字体对应的 Unicode 映射表。

  1. 创建自定义 IconSet 类

  2. 在生成时使用

📄 许可证

本项目遵循 Apache License 2.0 开源协议。


All versions of icon-captcha with dependencies

PHP Build Version
Package Version
Requires ext-gd Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package petalbranch/icon-captcha contains the following files

Loading the files please wait ...