initialize Project
This commit is contained in:
34
backend/app/src/Controllers/CaptchaController.php
Normal file
34
backend/app/src/Controllers/CaptchaController.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\lib\PCaptcha;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class CaptchaController
|
||||
{
|
||||
/**
|
||||
* Generates and outputs a captcha image.
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
$captcha = new PCaptcha();
|
||||
$captcha->width = 200;
|
||||
$captcha->hight = 50;
|
||||
$captcha->leng = 6;
|
||||
|
||||
try {
|
||||
$imageData = $captcha->get_captcha();
|
||||
} catch (\Throwable $e) {
|
||||
$response->getBody()->write("Captcha error: " . $e->getMessage());
|
||||
return $response->withStatus(500)->withHeader('Content-Type', 'text/plain');
|
||||
}
|
||||
|
||||
$response->getBody()->write($imageData);
|
||||
return $response->withHeader('Content-Type', 'image/png');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user