Download the PHP package zxf/captcha without Composer

On this page you can find all versions of the php package zxf/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 captcha

xfCaptcha - 高性能滑动验证码 & 点击验证码 PHP 扩展包

PHP Version [Version]()

高性能、安全、易用的滑动验证码 & 点击验证码 PHP 扩展包,支持 Laravel、ThinkPHP 等主流 PHP 框架,也可在原生 PHP 中使用。

效果展示

✨ 特性

📋 环境要求

📦 安装

通过 Composer 安装:

🚀 快速开始

Laravel 中使用(支持 Laravel 11+)

1. 安装服务提供者(Laravel 11+ 会自动发现)

注意:本包需要 Laravel 11.0 或更高版本。

对于需要手动注册的情况,在 bootstrap/providers.php 中注册服务提供者:

2. 发布配置文件

3. 在 Blade 模板中使用

Laravel 11 中引入 xfCaptcha 有三种方式:

方式一:使用 Blade 组件(推荐)

使用 @include 引入 Blade 组件,会自动在当前位置加载 CSS 和 JS 资源:

注意:Blade 组件会在 @include 的位置直接输出 <link><script> 标签。如果你需要将 JS 放在页面底部,请使用方式二手动引入资源。

方式二:手动引入资源(需要自定义时)

如果需要更多自定义控制(例如把 JS 放到页面底部),可以手动引入 CSS 和 JS:

方式三:使用资源混合(Laravel Mix/Vite)

如果使用 Laravel Mix 或 Vite 构建前端资源:

然后在 Blade 模板中:

Blade 组件参数说明

使用 @include('xf-captcha::captcha', [...]) 时可以传入以下参数:

参数 类型 默认值 说明
selector string 自动生成 触发元素的选择器
placeholder string 点击按钮进行验证 触发按钮的占位文字
slideText string 拖动左边滑块完成上方拼图 滑动提示文字
clickText string 请按照顺序点击图片中的文字 点击提示文字
successText string ✓ 验证成功 验证成功提示
failText string 验证失败,请重试 验证失败提示
inputName string xf_captcha_token 隐藏输入框的 name 属性
autoInsertInput bool true 验证成功后是否自动插入隐藏输入框
theme string auto 主题:lightdarkauto
showClose bool true 是否显示关闭按钮
showRefresh bool true 是否显示刷新按钮
showRipple bool true 是否显示水波纹效果
width string 自定义触发按钮宽度(如 100%260px
height string 自定义触发按钮高度(如 40px
borderRadius string 自定义触发按钮圆角(如 4px
onSuccess string 验证成功回调函数字符串,如 function(token) { ... }
onFail string 验证失败回调函数字符串
onClose string 弹窗关闭回调函数字符串
attributes string 额外的 HTML 属性字符串

4. 后端验证

ThinkPHP 中使用(支持 ThinkPHP 8+)

1. 配置

config/service.php 中添加:

2. 发布配置

3. 在模板中使用

4. 后端验证

原生 PHP 中使用

⚙️ 配置说明

完整配置示例

验证模式说明

1. frontend_only - 仅前端验证(不安全)

仅在前端进行滑动验证,不发送请求到后端。此模式仅用于测试,不推荐在生产环境使用

2. backend_only - 仅后端验证

传统的验证模式,用户滑动后前端发送位置到后端验证。验证通过后返回成功状态,并立即销毁 session 数据。

3. dual - 双重验证(推荐)

最安全的验证模式,流程如下:

滑动验证码流程

  1. 首次验证:用户滑动滑块,前端发送位置到后端
  2. 生成 Token:后端验证位置正确后,生成一次性 Token 返回
  3. 存储 Token:前端将 Token 存入隐藏输入框
  4. 二次验证:表单提交时,后端验证 Token 有效性
  5. 销毁 Token:Token 一次性使用,验证后立即销毁

点击验证码流程

  1. 首次验证:用户按顺序点击图片中的文字/符号,前端发送点击坐标到后端
  2. 生成 Token:后端验证点击顺序和位置正确后,生成一次性 Token 返回
  3. 存储 Token:前端将 Token 存入隐藏输入框
  4. 二次验证:表单提交时,后端验证 Token 有效性
  5. 销毁 Token:Token 一次性使用,验证后立即销毁

安全特性

🔌 JavaScript API

初始化

方法

事件回调

表单提交示例

🛡️ 安全建议

  1. 使用双重验证模式:生产环境请务必使用 dual 验证模式
  2. 启用 HTTPS:防止 Token 被中间人窃取
  3. 限制错误次数:合理设置 max_error_count 防止暴力破解
  4. 自定义背景图:使用自己的背景图片,增加识别难度
  5. 调整容错值:根据安全需求调整 fault_tolerance
  6. 及时重置:表单提交失败后及时调用 xfCaptcha.reset()
  7. Token 过期时间:根据业务需求调整 token_expire
  8. 请求指纹绑定:系统会自动绑定 User-Agent、IP、语言、编码和 Accept 指纹,并加入时间窗口,防止 Session 劫持
  9. 验证码过期机制:验证码生成后超过配置时间(默认 10 分钟)未验证将自动失效,需重新获取

🔧 常见问题

Q: 验证码图片不显示?

A: 请检查:

  1. GD 扩展是否安装:php -m | grep gd
  2. 背景图片目录是否存在且可读
  3. 路由配置是否正确
  4. 浏览器控制台是否有错误信息

Q: 验证总是失败?

A: 请检查:

  1. Session 是否正常启动
  2. 容错值是否设置过小(建议 3-5 像素)
  3. 浏览器是否支持 WebP(可强制使用 PNG)
  4. 服务器时间是否准确(影响 Token 过期判断)

Q: 移动端滑动卡顿?

A: 已针对移动端优化,如仍有问题请检查:

  1. 是否有其他 JavaScript 冲突
  2. 页面是否有大量重绘
  3. 是否使用了 touch-action: none 样式

Q: Token 验证失败?

A: 请检查:

  1. Token 是否在有效期内(默认5分钟)
  2. Token 是否已被使用过
  3. Session 是否正常
  4. 前端是否正确保存了 Token

Q: 如何自定义样式?

A: 可以通过覆盖 CSS 变量来自定义样式:

Q: 如何禁用关闭和刷新按钮?

A: 在初始化时设置:

📄 许可证

MIT License


All versions of captcha with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-gd Version *
ext-session Version *
ext-json 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 zxf/captcha contains the following files

Loading the files please wait ...