hedera-web/rest/misc/captcha.php

46 lines
995 B
PHP
Raw Normal View History

2016-07-22 20:00:27 +00:00
<?php
2018-05-23 10:14:20 +00:00
require_once('PEAR.php');
require_once('Text/CAPTCHA.php');
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
class Captcha extends Vn\Web\RestRequest {
function run($db) {
2016-07-22 20:00:27 +00:00
$options =
[
'width' => 130
,'height' => 45
,'output' => 'png'
,'imageOptions' =>
[
'font_size' => 20
,'font_path' => __DIR__
,'font_file' => 'IndieFlower.ttf'
,'text_color' => '#559955'
,'lines_color' => '#559955'
,'background_color' => '#DDDDDD'
,'antialias' => true
]
];
2018-05-23 10:14:20 +00:00
$captcha = Text_CAPTCHA::factory('Image');
$retval = $captcha->init($options);
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
if (PEAR::isError($retval))
throw new Exception('Error initializing CAPTCHA: %s!',
2016-07-22 20:00:27 +00:00
$retval->getMessage());
2018-05-23 10:14:20 +00:00
$png = $captcha->getCAPTCHA();
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
if (PEAR::isError($png))
throw new Exception('Error generating CAPTCHA: %s!',
$png->getMessage());
2016-07-22 20:00:27 +00:00
// Get secret passphrase
2018-05-23 10:14:20 +00:00
$_SESSION['captcha'] = $captcha->getPhrase();
2016-07-22 20:00:27 +00:00
2018-05-23 10:14:20 +00:00
header('Content-Type: image/png');
2016-07-22 20:00:27 +00:00
echo $png;
}
}