williamsampaio/simple-captcha 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

williamsampaio/simple-captcha

Composer 安装命令:

composer require williamsampaio/simple-captcha

包简介

Simple class that implement a CAPTCHA for your PHP App

README 文档

README

Simple class that implement a CAPTCHA for your PHP App.

GitHub GitHub release (latest SemVer)

Installation

Use the package manager composer to install.

composer require williamsampaio/simple-captcha

Documentation

1. Create new Captcha

 $captcha = new SimpleCaptcha();

If no parameters are passed the captcha code will be automatically generated with a length of 5 numeric characters.

But it is possible to pass two parameters. The first is a string with the captcha code (maximum length of 16 characters), the second is a boolean to generate random colors if true.

 $captcha = new SimpleCaptcha("H@ck3R'D_C0@r1", true);

2. Get the captcha code

 $captcha->getKey();

3. Get the captcha image

<img src="<?php echo $captcha->getImg() ?>" />

Example

A simple usage example.

<?php

require __DIR__ . '/../vendor/autoload.php';

use WilliamSampaio\SimpleCaptcha\SimpleCaptcha;

session_start();

$captcha = new SimpleCaptcha();

if(isset($_POST['captcha'])){

    if($_POST['captcha'] == $_SESSION['captcha']->getKey()){
        echo "<h1 style='color:green;'>Captcha valid! (".$_POST['captcha'] ."=". $_SESSION['captcha']->getKey().")</h1>";
    }else{
        echo "<h1 style='color:red;'>Captcha invalid! (".$_POST['captcha'] ."=". $_SESSION['captcha']->getKey().")</h1>";
    }

}

$_SESSION['captcha'] = $captcha;

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="post">
        <img src="<?= $captcha->getImg() ?>"/>
        <br>
        <input type="text" name="captcha" id="captcha">
        <hr>
        <input type="submit" value="Check">
    </form>
</body>
</html>

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固