joeyjophi/php-image-captcha

简单 & 安全的 PHP 图形验证码

v1.0.x-dev 2022-12-07 07:16 UTC

This package is auto-updated.

Last update: 2024-09-07 11:11:07 UTC


README

简单 & 安全的 PHP 图形验证码

用法/示例

sample-form.php

<html>
  <head>
    <title>Simple Captcha</title>
  </head>
  <body>
    <center>
    <form method="post" action="formSubmit.php">
        <button type="button" onclick="document.getElementById('captchaImage').src = 'generateCaptcha.php?' + new Date().getTime();">Refresh Captcha</button>
        <br/><br/>
        <img src="generateCaptcha.php?<?php time();?>" id="captchaImage" />
        <br/><br/>
        <input type="text" id="captcha" name="captcha" />
        <br/><br/>
        <button type="submit">Submit</button>
    </form>
    </center>
  </body>
</html>

generateCaptcha.php

<?php

require_once 'vendor/autoload.php';

$captcha = new \Joejophi\PhpImageCaptcha\Captcha();
return $captcha->generate();

formSubmit.php

<?php

require_once 'vendor/autoload.php';

$captcha = new \Joejophi\PhpImageCaptcha\Captcha();

if (isset($_POST["captcha"])) {
    if ($captcha->verify($_POST["captcha"])) {
        echo "Valid Captcha";
    } else {
        echo "Invalid Valid Captcha";
    }
}

作者

  • N M Jophi

特性

  • 易于集成
  • 几秒钟内即可在任何表单上添加简单 & 安全的 PHP 验证码
  • 生成的图形验证码是字母和数字的组合
  • 用于防止垃圾邮件