A difficult question. the verification code is not displayed.

Source: Internet
Author: User
A difficult question: the verification code is not displayed. this post is Last edited by ziluoapo4 from 2014-10-12:33:16. the general verification code is not displayed. The reason is: 1 & nbsp; there is a BOM & nbsp; header, 2 & nbsp; extensionphp_gd2.dll is not enabled (that is, remove the semicolon), but this is not the above two reasons, because I have checked. A difficult problem. the verification code is not displayed.

This post was last edited by ziluoapo4 at 17:33:16

Generally, the verification code is not displayed. nowhere is it because: 1 has a BOM header, and 2 extension = php_gd2.dll is not enabled (that is, remove the semicolon)

But I am not the above two reasons, because I have checked.
There is a solution in the forum that is to add ini_set ('display _ errors ', 'off') at the beginning of the page; I also add, (see this post: http://bbs.csdn.net/topics/350011289) or not,
However, it is strange that other cms programs show verification codes. The php Version I use is PHP Version 5.3.28.
What if I say this is a difficult problem?

------ Solution ----------------------
Modified it. OK, mainly in the font. you have not defined the ROOT_PATH, so you cannot get $ this-> font = ROOT_PATH. '/font/elephant. ttf ';
You can change the ROOT_PATH to the correct path in define mode. now the test directory is like this.
Test. php
Font/elephant. ttf
Set ROOT_PATH in test. php to define ('root _ path', dirname (_ FILE __));

The complete test code is as follows:

// Verification code
Define ('root _ path', dirname (_ FILE __));

// Verification code
Class ValidateCode {
Private $ charset = 'abcdefghkmnprstuvwxyzabcdefghkmnprstuvwxyz23456789 '; // random factor
Private $ code; // verification code
Private $ codelen = 4; // verification code length
Private $ width = 130; // width
Private $ height = 50; // height
Private $ img; // graphical resource handle
Private $ font; // The specified font.
Private $ fontsize = 20; // specify the font size
Private $ fontcolor; // specifies the font color.

// Constructor initialization
Public function _ construct (){
$ This-> font = ROOT_PATH. '/font/elephant. ttf ';
}

// Generate random code
Private function createCode (){
$ _ Len = strlen ($ this-> charset)-1;
For ($ I = 0; $ I <$ this-> codelen; $ I ++ ){
$ This-> code. = $ this-> charset [mt_rand (0, $ _ len)];
}
}

// Generate background
Private function createBg (){
$ This-> img = imagecreatetruecolor ($ this-> width, $ this-> height );
$ Color = imagecolorallocate ($ this-> img, mt_rand (157,255), mt_rand (157,255), mt_rand (157,255 ));
Imagefilledrectangle ($ this-> img, 0, $ this-> height, $ this-> width, 0, $ color );
}

// Generate text
Private function createFont (){
$ _ X = $ this-> width/$ this-> codelen;
For ($ I = 0; $ I <$ this-> codelen; $ I ++ ){
$ This-> fontcolor = imagecolorallocate ($ this-> img, mt_rand (0,156), mt_rand (0,156), mt_rand (0,156 ));
Imagettftext ($ this-> img, $ this-> fontsize, mt_rand (-30, 30), $ _ x * $ I + mt_rand (1.4), $ this-> height, $ this-> fontcolor, $ this-> font, $ this-> code [$ I]);
}
}

// Generate lines and snowflakes
Private function createLine (){
For ($ I = 0; $ I <6; $ I ++ ){
$ Color = imagecolorallocate ($ this-> img, mt_rand (0,156), mt_rand (0,156), mt_rand (0,156 ));
Imageline ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ color );
}
For ($ I = 0; I I <100; $ I ++ ){

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.