<?php
Class Ctl_admin_captcha extends ssc_controler{
Public Function Index ()
{
Load the Captcha class and set the session
$captcha = $this->load->library (' Validatecode ');
$captcha->gencodeimage ();
$_session[' captcha '] = $captcha->getcode ();
}
}
/*
* Verification code class, need to load font file
*
* */
Class Ssc_validatecode
{
Private $charset = "abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ3456789";
Private $code;
Private $codelen = 4;
Private $width = 150;
Private $height = 50;
Private $img;
Private $font;
Private $fontsize = 18;
Private $fontcolor;
Public Function __construct ()
{
if (!function_exists ("Imagecreatetruecolor") | | |!function_exists ("imagecolorallocate") | |!function_exists (" Imagefilledrectangle ") | | !function_exists ("Imagettftext") | | !function_exists ("Imageline") | | !function_exists ("imagestring")) {
return false;
}
$this->font = "/latinwd. TTF ";
if (!file_exists ($this->font)) {
return false;
}
}
Public Function __destruct ()
{
if (Isset ($this->img)) {
unset ($this->img);
$this->img = NULL;
}
if (Isset ($this->font)) {
unset ($this->font);
$this->font = NULL;
}
}
Private Function Createcode ()
{
$_len = strlen ($this->charset)-1;
for ($i = 0; $i < $this->codelen; $i + +) {
$this->code. = $this->charset[mt_rand (0, $_len)];
}
}
Private Function CREATEBG ()
{
$this->img = Imagecreatetruecolor ($this->width, $this->height);
$color = Imagecolorallocate ($this->img, 255, 255, 255);
Imagefilledrectangle ($this->img, 0, $this->height, $this->width, 0, $color);
}
Private Function CreateFont ()
{
$_x = $this->width/$this->codelen;
for ($i = 0; $i < $this->codelen; $i + +) {
$this->fontcolor = imagecolorallocate ($this->img, 0, 0, 0);
Imagettftext ($this->img, $this->fontsize, Mt_rand ( -25), ($_x * $i) + mt_rand (1, 3), $this->height/1.4, $thi S->fontcolor, $this->font, Strtoupper ($this->code[$i]));
}
}
Private Function Createline ()
{
for ($i = 0; $i < $i + +) {
$color = Imagecolorallocate ($this->img, 0, 0, 0);
Imageline ($this->img, Mt_rand (0, $this->width), Mt_rand (0, $this->height), Mt_rand (0, $this->width), Mt_ Rand (0, $this->height), $color);
}
for ($i = 0; $i < 6; $i + +) {
$color = Imagecolorallocate ($this->img, 0, 0, 0);
Imagestring ($this->img, Mt_rand (1, 5), Mt_rand (0, $this->width), Mt_rand (0, $this->height), "*", $color);
}
}
Private Function OutPut ()
{
Ob_clean ();
Header ("Content-type:image/png");
Imagepng ($this->img);
Imagedestroy ($this->img);
}
Public Function Gencodeimage ()
{
$this->CREATEBG ();
$this->createcode ();
$this->createline ();
$this->createfont ();
$this->output ();
return true;
}
Public Function GetCode ()
{
Return Strtolower ($this->code);
}
}
?>
PHP Verification Code Class