Php5 verification code class (simple and practical)

Source: Internet
Author: User
Php5 verification code class (simple and practical)
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 () ;?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.