Php verification code file class _ php tips-php Tutorial

Source: Internet
Author: User
This article mainly introduces the verification code file class implemented by php. The example analyzes the skills of php to generate the verification code file, which is of great practical value, you can refer to the example in this article to describe the verification code file class implemented by php. Share it with you for your reference. The details are as follows:

<? Php/*** @ file * @ version 1.0 * @ author @ * @ brief verification code file class **/class CCheckCodeFile {// Number of verification code digits private $ mCheckCodeNum = 4; // The generated verification code is private $ mCheckCode = ''; // the verification code picture is private $ mCheckImage =''; // The interference pixel is private $ mDisturbColor = ''; // the image width of the verification code is private $ mCheckImageWidth = '80'; // the image width of the verification code is private $ mCheckImageHeight = '20 '; /***** @ brief output header **/private function OutFileHeader () {header ("Content-type: image/png");}/***** @ bri Ef generates the verification code **/private function CreateCheckCode () {$ this-> 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. **/p Rivate 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; $ t His-> mCheckImageWidth = $ width; $ this-> mCheckImageHeight = $ height; return true ;} /***** @ brief Upload the verification code one by one on the verification code Image **/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-> SetChec KImageWH (); // set the size of the image displaying the verification code $ c_check_code_image-> OutCheckImage ();?>

I hope this article will help you with php programming.

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.