php-captcha/captcha

php 图形验证码

安装: 54

依赖关系: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:项目

1.0 2017-03-22 08:18 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:42:12 UTC


README

php 图形验证码,需要 GD 扩展。

需要

Predis

安装

composer.json

require: {
    "php-captcha/captcha": "~1.0"
}

示例

  • 使用 base64 字符串

      use Captcha\CaptchaManager
      
      $redisClient = ...;
      $identity = ...;
      
      $captcha = new CaptchaManager($redisClient);
      
      $base64ImageString = $captcha->createBase64ImageCaptcha($identity);
      
      $response = ...;
      
      $response->setBody($base64ImageString);
      
      return $response;
    
  • 使用 content-type:image/png

      use Captcha\CaptchaManager
      
      $redisClient = ...;
      $identity = ...;
      
      $captcha = new CaptchaManager($redisClient);
      
      $captcha->createStreamImageCaptcha($identity);
      
      $response = ...;
      
      $response->headers->add([Content-type' => 'image/png']);
      
      return $response;