PHP code example of lorddashme / php-simple-captcha
1. Go to this page and download the library: Download lorddashme/php-simple-captcha library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lorddashme / php-simple-captcha example snippets
ordDashMe\SimpleCaptcha\Captcha;
// Initialize the captcha class.
$captcha = new Captcha();
// Execute the random generation of code.
$captcha->code();
// Execute the image captcha rendering.
$captcha->image();
// The generated captcha code, something like "QwErTyx..."
echo $captcha->getCode();
// The generated captcha image that
ordDashMe\SimpleCaptcha\Facade\Captcha;
// Initialize the facade captcha class.
Captcha::init();
// Execute the random generation of code.
Captcha::code();
// Execute the image captcha rendering.
Captcha::image();
// The generated captcha code, something like "QwErTyx..."
echo Captcha::getCode();
// The generated captcha image that
// login.php
a\Captcha;
$captcha = new Captcha();
$captcha->code();
$captcha->image();
$captcha->storeSession();
// validate-login.php
;
$captcha = new Captcha();
$data = $captcha->getSession(); // return array( 'code' => 'QwErTyx...' )
if ($_POST['user_captcha_code'] === $data['code']) {
return 'Code is valid!';
} else {
return 'Code is invalid!';
}
ordDashMe\SimpleCaptcha\Captcha;
use LordDashMe\SimpleCaptcha\Facade\Captcha as CaptchaFacade;
$config = array(
'session_name' => 'ldm-simple-captcha',
'session_index_name' => 'LDM_SIMPLE_CAPTCHA',
'session_https' => false,
'session_http_only' => true,
'font_color' => '#000',
'font_size_min' => 26,
'font_size_max' => 28,
'angle_min' => 0,
'angle_max' => 9,
'shadow' => true,
'shadow_color' => '#fff',
'shadow_offset_x' => -3,
'shadow_offset_y' => 1,
'backgrounds' => array(
'bg1.png',
'bg2.png',
'bg3.png',
'bg4.png',
'bg5.png',
'bg6.png',
'bg7.png',
'bg8.png'
),
'fonts' => array(
'capsmall_clean.ttf'
)
);
$captcha = new Captcha($config);
// Or you can use this style.
CaptchaFacade::init($config);
ashMe\SimpleCaptcha\Captcha;
class MyNewCaptcha extends Captcha
{
public function __construct($config = array())
{
parent::__construct($config);
}
protected function backgroundsDirectoryPath()
{
return 'path/to/your/custom/backgrounds/';
}
protected function fontsDirectoryPath()
{
return 'path/to/your/custom/fonts/';
}
}
txt
composer
array('code' => '...')
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.