cleup/captcha
最新稳定版本:v1.0.2
Composer 安装命令:
composer require cleup/captcha
包简介
Basic captcha
README 文档
README
Basic captcha for project security
Installation
With composer:
composer require cleup/captcha
Usage
Create an image
Create a captcha image and place it in a controller file or on a separate page of your application:
use Cleup\Package\Captcha\Image; # Instance of the class $captcha = new Image([ # Captcha Parameters 'width' => 300, 'height' => 60, /* You can set a range for these parameters using various methods (rand, random_int) */ // 'length' => 5, // 'fontSize' => 24, // 'allowedCharacters' => '1234567890abcdefghijkmnpqrstuvwxyz', // 'width' => 140, // 'height' => 60, // 'maxLines' => 8, // 'minLines' => 4, // 'pointColor' => array(77, 77, 77), // 'textColor' => array( // rand(0, 78), // rand(0, 100), // rand(0, 7) // ) ]); // Create a captcha image $captcha->create(); /* The end of the file. */
Output data on html page
... <img src="/image.php" alt="Captcha"/> // Or <img src="/captcha/image.php?<?= rand(10, 1000); ?>" alt="Captcha"/> ...
Code verification
Code verification works using sessions. Make sure that the session is initiated and available for recording:
use Cleup\Package\Captcha\Verification; # Instance of the class $verification = new Verification(); // Raw data $data = json_decode( file_get_contents('php://input'), true ); // Getting the code $code = $data['code'] ?? false; if (!$code) { $response = [ 'success' => false, 'message' => 'You have not entered the required data' ]; } else { if ($verification->verify($code)) { $response = [ 'success' => true, 'message' => 'The code is correct' ]; } else { $response = [ 'success' => false, 'message' => 'The code is incorrect' ]; } } header('Content-type: application/json'); echo json_encode($response);
If you have any difficulties, then study the demo version of the project in the demo folder
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-22