mobicms/captcha

简单的PHP CAPTCHA库

4.0.0 2022-12-09 13:22 UTC

This package is auto-updated.

Last update: 2024-09-25 12:41:05 UTC


README

GitHub GitHub release (latest SemVer) Packagist

CI-Analysis CI-Tests Sonar Coverage Quality Gate Status

这个库是一个简单的PHP CAPTCHA。通过生成随机的CAPTCHA图像来防止表单垃圾邮件。

主要特性

  • 轻量级且快速
  • 不会创建任何临时文件
  • 有许多设置可以更改图片的外观
  • 可以自定义字体

示例

Captchas examples

安装

推荐通过 Composer 安装。运行以下命令来安装包并将其添加到项目的 composer.json 文件中:

composer require mobicms/captcha

用法

  • 在表单中显示
<?php
$code = (string) new Mobicms\Captcha\Code;
$_SESSION['code'] = $code;
?>

<form method="post">
<!-- ... -->
<img alt="Verification code" src="<?= new Mobicms\Captcha\Image($code) ?>">
<input type="text" size="5" name="code">
<!-- ... -->
</form>
  • 检查输入的代码是否正确
$result = filter_input(INPUT_POST, 'code');
$session = filter_input(INPUT_SESSION, 'code');

if ($result !== null && $session !== null) {
    if (strtolower($result) == strtolower($session)) {
        // CAPTCHA code is correct
    } else {
        // CAPTCHA code is incorrect, show an error to the user
    }
}

贡献

欢迎贡献!请阅读 贡献指南 以获取详细信息。

YAGNI KISS

在开发过程中,我们遵循 YAGNIKISS 原则。源代码不应包含额外的非必要功能,应尽可能简单和高效。

许可证

本软件包受MIT许可证(MIT)的许可。
有关更多信息,请参阅 LICENSE

我们的链接