Practical PHP verification code (12 ). Verification codes are indispensable in application development. we often encounter issues related to registration by machines, so with verification codes, this type of behavior can be effectively prevented, next, let's take a look at the verification code that I provided in this development application. we often encounter issues related to being registered by machines, so the verification code can effectively prevent such behaviors, next let's take a look at the code I provided.
Verification codes are indispensable in application development. we often encounter problems related to registration by machines, so the verification code can effectively prevent such behaviors. let's take a look at the code I provided.
Session_start ();
Class authnum {
// Image object, width, height, and verification code length
Private $ im;
Private $ im_width;
Private $ im_height;
Private $ len;
// Random string, Y axis coordinate value, and random color
Private $ randnum;
Private $ y;
Private $ randcolor;
// The red, green, and blue background color. the default value is light gray.
Public $ red= 238;
Public $ green = 238;
Public $ blue = 238;
/**
* Optional settings: verification code type, interference point, interference line, and y-axis random
* If it is set to false, this parameter is disabled.
**/
// The default value is a combination of upper and lower case numbers. the value 1 2 3 indicates lower case, upper case, and number type respectively.
Public $ ext_num_type = '';
Public $ ext_pixel = false; // interference point
Public $ ext_line = false; // interference line
Public $ ext_rand_y = true; // random Y axis
Function _ construct ($ len = 4, $ im_width = '', $ im_height = 25 ){
// The verification code length, image width, and height are required for class instantiation.
$ 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 the background color of the image. the default value is light gray.
Function set_bgcolor (){
Imagecolorallocate ($ this-> im, $ this-> red, $ this-> green, $ this-> blue );
}
// Obtain random digits
Function get_randnum (){
$ An1 = 'abcdefghijklmnopqrstuvwxy ';
$ An2 = 'abcdefghijklmnopqrstuvwxy ';
$ An3 = '20140901 ';
If ($ this-> ext_num_type = '') $ str = $ an1. $ an2. $ an3;
If ($ this-> ext_num_type = 1) $ str = $ an1;
If ($ this-> ext_num_type = 2) $ str = $ an2;
If ($ this-> ext_num_type = 3) $ str = $ an3;
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;
}
// Obtain the verification code Image 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
...