Copy CodeThe code is as follows:
Class Code
{
var $width = 160; The width of the picture
var $hight = 40; Picture of the High
var $image;
var $red = 223; RGB color of the picture
var $green = 225; Red
var $blue = 227;//Green
var $pix = 227;//Blue
var $pixcolor; Noise color;
var $pixred = 242; Red
var $pixgreen = 168;//Green
var $pixblue = 162; Blue
var $txt =null;//Verification Code text
var $txtcode =null;
var $txtsub =null;
var $pixnum = 300; Number of miscellaneous points
var $i = 0;
var $widthpx = 0;
var $highty = 0;
var $txtreg = 50;
var $txtgreen = 30;
function createimage ()//Create a picture and fill the color
{
$this->image = imagecreate ($this->width, $this->hight);
$this->color = imagecolorallocate ($this->image, $this->red, $this->green, $this->blue);
Return Imagefill ($this->image,0,0, $this->color);
}
function Createpix ()//interference factor
{
For ($this->i=1; $this->i< $this->pixnum; $this->i++)
{
$this->widthpx = rand (0, $this->width);
$this->highty = rand (0, $this->hight);
$this->pixcolor = imagecolorallocate ($this->image, $this->pixred, $this->pixgreen, $this->pixblue);
Imagesetpixel ($this->image, $this->widthpx, $this->highty, $this->pixcolor);
}
}
function Gettxt ()//Create CAPTCHA text
{
$this->txt = Array ("I", "Love", "You", "leaves", "on", "Hui", "Ming", "FA", "true", "the", "very", "want", "no", "know", "to", "for", "what", "what", "on", "Yes", "Forget", "no", "the "You", "also", "Xu", "Shang", "generation", "owe", "money");
For ($this->i=0; $this->i<6; $this->i++)
{
$this->sub = $this->txt[rand (0,29)];
$this->txtcode.= $this->sub;
}
$this->txtcode = Iconv ("GB2312", "UTF-8", $this->txtcode);
$_session["code"] = $this->txtcode; The resulting validation ID
}
function createstring ()//create CAPTCHA Picture
{
Imagettftext ($this->image,20,5,0,40, $this->pixcolor, "C:\WINDOWS\FONTS\SIMSUN.TTC", $this->txtcode);
Header ("Content-type:image/png");
Return Imagepng ($this->image);
Imagedestroy ($this->image);
}
function getcodeimage ()//Get Verification code picture
{
$this->createimage ();
$this->gettxt ();
$this->createpix ();
$this->createstring ();
}
}
?>
Session_Start ();
$text = new Code;
$text->createimage ();
$text->gettxt ();
$text->createpix ();
$text->createstring ();
?>
http://www.bkjia.com/PHPjc/317245.html www.bkjia.com true http://www.bkjia.com/PHPjc/317245.html techarticle Copy the code as follows:? PHP Classcode {var$width=160;//Picture of the wide var$hight=40;//picture of the high var$image; var$red=223;//the RGB color of the picture var$green= 225;//Red var$blue=227;//Green ...