Development of the application of the verification code is not necessary, we often touch on the machine registration, then have a verification code can effectively prevent such behavior, let's look at the code I provide.
Development of the application of the verification code is not necessary, we often touch on the machine registration, then have a verification code can effectively prevent such behavior, let's look at the code I provide.
Session_Start ();
Class Authnum {
Picture object, width, height, captcha length
Private $im;
Private $im _width;
Private $im _height;
Private $len;
Random string, y coordinate value, random color
Private $randnum;
Private $y;
Private $randcolor;
Red, green and blue background color, light gray by default
Public $red = 238;
Public $green = 238;
Public $blue = 238;
/**
* Optional Settings: Verification code type, interference point, interference line, y-axis random
* Set to False indicates not enabled
**/
The default is case-number mixed, 1 2 3 for lowercase, uppercase, and numeric
Public $ext _num_type= ';
Public $ext _pixel = false; Interference Point
Public $ext _line = false; Interference Line
Public $ext _rand_y= true; Y-Axis random
function __construct ($len =4, $im _width= ", $im _height=25) {
Verification code length, image width, height is the data required to instantiate the class
$this->len = $len; $im _width = $len * 15;
$this->im_width = $im _width;
$this->im_height= $im _height;
$this->im = imagecreate ($im _width, $im _height);
}
Set picture background color, default is light gray background
function Set_bgcolor () {
Imagecolorallocate ($this->im, $this->red, $this->green, $this->blue);
}
Get random numbers of arbitrary digits
function Get_randnum () {
$an 1 = ' abcdefghijklmnopqrstuvwxyz ';
$an 2 = ' abcdefghijklmnopqrstuvwxyz ';
$an 3 = ' 0123456789 ';
if ($this->ext_num_type = = ") $str = $an 1. $an 2. $an 3;
if ($this->ext_num_type = = 1) $str = $an 1;
if ($this->ext_num_type = = 2) $str = $an 2;
if ($this->ext_num_type = = 3) $str = $an 3;
for ($i = 0; $i < $this->len; $i + +) {
$start = rand (1,strlen ($STR)-1);
$randnum. = substr ($str, $start, 1);
}
$this->randnum = $randnum;
$_session[an] = $this->randnum;
}
Get Verification code Picture Y axis
function get_y () {
if ($this->ext_rand_y) $this->y = rand (5, $this->IM_HEIGHT/5);
else $this->y = $this->IM_HEIGHT/4;
}
1 2
http://www.bkjia.com/PHPjc/444817.html www.bkjia.com true http://www.bkjia.com/PHPjc/444817.html techarticle development of the application of the verification code is not necessary, we often touch on the machine registration, then there is a verification code can effectively prevent such behavior, let's look at the I offer this ...