Let's share a beautiful php Verification Code class. For more information, see!
Php Verification Code
Width = $ width;
$ This-> height = $ height;
$ This-> counts = $ counts;
$ This-> distrubcode = $ distrubcode;
$ This-> fonturl = $ fonturl;
$ This-> session = $ this-> sessioncode ();
Session_start ();
$ _ SESSION ["code"] = $ this-> session;
}
Function imageout (){
$ Im = $ this-> createimagesource ();
$ This-> setbackgroundcolor ($ im );
$ This-> set_code ($ im );
$ This-> setdistrubecode ($ im );
ImageGIF ($ im );
ImageDestroy ($ im );
}
Private function createimagesource (){
Return imagecreate ($ this-> width, $ this-> height );
}
Private function setbackgroundcolor ($ im ){
$ Bgcolor = ImageColorAllocate ($ im, rand (200,255), rand (200,255), rand (200,255); // ± 3? ° ?? ?
Imagefill ($ im, 0, 0, $ bgcolor );
}
Private function setdistrubecode ($ im ){
$ Count_h = $ this-> height;
$ Cou = floor ($ count_h * 2 );
For ($ I = 0; $ I <$ cou; $ I ++ ){
$ X = rand (0, $ this-> width );
$ Y = rand (0, $ this-> height );
$ Jiaodu = rand (0,360 );
$ Fontsize = rand (8, 15 );
$ Fonturl = $ this-> fonturl;
$ Originalcode = $ this-> distrubcode;
$ Countdistrub = strlen ($ originalcode );
$ Dscode = $ originalcode [rand (0, $ countdistrub-1)];
$ Color = ImageColorAllocate ($ im, rand (40,140), rand (40,140), rand (40,140 ));
Imagettftext ($ im, $ fontsize, $ jiaodu, $ x, $ y, $ color, $ fonturl, $ dscode );
}
}
Private function set_code ($ im ){
$ Width = $ this-> width;
$ Counts = $ this-> counts;
$ Height = $ this-> height;
$ Scode = $ this-> session;
$ Y = floor ($ height/2) + floor ($ height/4 );
$ Fontsize = rand (30, 35 );
$ Fonturl = "C: \ Windows \ Fonts \ AdobeGothicStd-Bold.otf"; // $ this-> fonturl;
$ Counts = $ this-> counts;
For ($ I = 0; $ I <$ counts; $ I ++ ){
$ Char = $ scode [$ I];
$ X = floor ($ width/$ counts) * $ I + 8;
$ Jiaodu = rand (-20, 30 );
$ Color = ImageColorAllocate ($ im, rand (50,100), rand (100,140 ));
Imagettftext ($ im, $ fontsize, $ jiaodu, $ x, $ y, $ color, $ fonturl, $ char );
}
}
Private function sessioncode (){
$ Originalcode = $ this-> distrubcode;
$ Countdistrub = strlen ($ originalcode );
$ _ Dscode = "";
$ Counts = $ this-> counts;
For ($ j = 0; $ j <$ counts; $ j ++ ){
$ Dscode = $ originalcode [rand (0, $ countdistrub-1)];
$ _ Dscode. = $ dscode;
}
Return $ _ dscode;
}
}
The PHP verification code example demonstrates how to create an output file code:
Header ("Content-type: image/GIF ");
$ Imagecode = new Imagecode (150,2 );
$ Imagecode-> imageout ();
PHP Verification Code class is so simple and can be used!
Source code.