| We will introduce you to a php verification code class, which is simple and practical and can be used as a reference.
PHP verification code.
MCheckCode = strtoupper (substr (md5 (rand (), 0, $ this-> mCheckCodeNum); return $ this-> mCheckCode ;} /***** @ brief generate verification code Image **/private function CreateImage () {$ this-> mCheckImage = @ imagecreate ($ this-> mCheckImageWidth, $ this-> mCheckImageHeight); imagecolorallocate ($ this-> mCheckImage, 200,200,200); return $ this-> mCheckImage ;} /***** @ brief sets the interference pixels of the image. **/private function SetDisturbColor () {for ($ I = 0; $ I <= 128; $ I + +) {$ This-> mDisturbColor = imagecolorallocate ($ this-> mCheckImage, rand (0,255), rand (0,255), rand (0,255 )); imagesetpixel ($ this-> mCheckImage, rand (2,128), rand (), $ this-> mDisturbColor );}} /***** @ brief sets the size of the verification code Image ** @ param $ width ** @ param $ height **/public function SetCheckImageWH ($ width, $ height) {if ($ width = ''| $ height ='') return false; $ this-> mCheckImageWidth = $ width; $ this-> mCheckImageHeigh T = $ height; return true;}/***** @ brief on the verification code image to draw the verification code one by one **/private function WriteCheckCodeToImage () {for ($ I = 0; $ I <= $ this-> mCheckCodeNum; $ I ++) {$ bg_color = imagecolorallocate ($ this-> mCheckImage, rand (0,255), rand (0,128 ), rand (0,255); $ x = floor ($ this-> mCheckImageWidth/$ this-> mCheckCodeNum) * $ I; $ y = rand (0, $ this-> mCheckImageHeight-15); imagechar ($ this-> mCheckImage, 5, $ x, $ y, $ this-> mCheckCode [$ I], $ Bg_color) ;}}/***** @ brief output verification code Image **/public function OutCheckImage () {$ this-> OutFileHeader (); $ this-> CreateCheckCode (); $ this-> CreateImage (); $ this-> SetDisturbColor (); $ this-> WriteCheckCodeToImage (); imagepng ($ this-> mCheckImage); imagedestroy ($ this-> mCheckImage) ;}$ c_check_code_image = new CCheckCodeFile (); // $ c_check_code_image-> SetCheckImageWH ); // set the image size for displaying the verification code $ c_check_code_image-> Ou TCheckImage () ;?> |