Php verification code and cannot display solution results normally? All files are stored in the same folder .? CreateImage. class. php & lt ;? PhpclassValidationCode {private $ width, $ height, $ codenum; public $ checkcode php verification code and abnormal display solution
Effect
?
All files are stored in the same folder.
?
CreateImage. class. php
Width = $ width; $ this-> height = $ height; $ this-> codenum = $ codenum;} function outImg () {// output header $ this-> outFileHeader (); // Generate a verification code $ this-> createCode (); // generate an image $ this-> createImage (); // Set the interference pixel $ this-> setDisturbColor (); // write the verification code to the image $ this-> writeCheckCodeToImage (); imagepng ($ this-> checkimage ); imagedestroy ($ this-> checkimage);} private function outFileHeader () {header ('content-type: image/png ');} private function createCode () {$ this-> checkcode = strtoupper (substr (md5 (rand (), 0, $ this-> codenum);} private function createImage () {$ this-> checkimage = @ imagecreate ($ this-> width, $ this-> height); $ back = imagecolorallocate ($ this-> checkimage, 255,255,255 ); $ border = imagecolorallocate ($ this-> checkimage, 0); imagefilledrectangle ($ this-> checkimage, $ this-> width-1, $ this-> height-1, $ back); // white background imagerectangle ($ this-> checkimage, 0, 0, $ this-> width-1, $ this-> height-1, $ border); // black border} private function setDisturbColor () {for ($ I = 0; $ I <= 200; $ I ++) {$ this-> disturbColor = imagecolorallocate ($ this-> checkimage, rand (0,255), rand (0,255), rand (0,255 )); imagesetpixel ($ this-> checkimage, rand (2,128), rand (2, 38), $ this-> disturbColor) ;}} private function writeCheckCodeToImage () {for ($ I = 0; $ I <= $ this-> codenum; $ I ++) {$ bg_color = imagecolorallocate ($ this-> checkimage, rand (0,255), rand (0,128 ), rand (0,255); $ x = floor ($ this-> width/$ this-> codenum) * $ I; $ y = rand (0, $ this-> height-15); imagechar ($ this-> checkimage, rand (5, 8), $ x, $ y, $ this-> checkcode [$ I], $ bg_color) ;}} function _ destruct () {unset ($ this-> width, $ this-> height, $ this-> codenum );}}
?
Checks. php
?
?
Index. php
?
Application of rand functions
?
* *********************************** Problems *************
?
?
?
1. php_gd2.dll not enabled? Remove ";" in front of php. ini.
2. in the preceding checks. php
3. change character encoding to uniform
4. the easiest thing to ignore:
? In your local environment, all error messages are displayed. Therefore, the undefined information of the system is output along with the output. in this way, the generated image is not normal, there are two methods in ValidationCode. php and checks. add ini_set ('display _ errors ',? 'Off ');?? OK.
?
?
?
**************************************** ******************
?