Operation Result:
<!--vcode.class.php Content--
<?php
Class Vcode {
Private $width; Wide
Private $height; High
Private $num; Number
Private $code; Verification Code
Private $img; Resources for images
Construction method, three parameters
function __construct ($width, $height, $num) {
$this->width = $width;
$this->height = $height;
$this->num = $num;
$this->code = $this->createcode (); Call your own method
}
Gets the verification code for the character to be saved in the server
function GetCode () {
return $this->code;
}
Output image
function outimg () {
Create background (color, size, border)
$this->createback ();
stooped (size, font color)
Interference elements (points, lines)
Output image
$this->printimg ();
}
Create a background
Private Function Createback () {
Create a resource
$this->img = Imagecreatetruecolor ($this->width, $this->height);
Set a random background color
$bgcolor = Imagecolorallocate ($this->img, rand (225, 255), rand (225, 255), rand (225, 255));
Set Background fill
Imagefill ($this->img, 0, 0, $bgcolor);
Draw Border
$bordercolor = Imagecolorallocate ($this->img, 0, 0, 0);
Imagerectangle ($this->img, 0, 0, $this->width-1, $this->height-1, $bordercolor);
}
Stooped
Private Function outstring () {
}
Setting interference elements
Private Function Setdisturbcolor () {
}
Output image
Private Function printimg () {
if (Imagetypes () & Img_gif) {
Header ("Content-type:image/gif");
Imagegif ($this->img);
} elseif (Function_exists ("imagejpeg")) {
Header ("Content-type:image/jpeg");
Imagegif ($this->img);
} elseif (Imagetypes () & Img_png) {
Header ("Content-type:image/png");
Imagegif ($this->img);
} else {
Die ("No image, support in this PHP server");
}
}
Generate Authenticode String
Private Function Createcode () {
$codes = "3456789abcdefghijkmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY";
$code = "";
for ($i =0; $i < $this->num; $i +) {
$code. = $codes {rand (0, strlen ($codes)-1)};
}
return $code;
}
For automatic destruction of image resources
function __destruct () {
Imagedestroy ($this->img);
}
}
Verification code class in PHP (second verification code function design)