A difficult problem. the verification code is not displayed.

Source: Internet
Author: User
A difficult problem. Generally, the verification code is not displayed because: 1 has a BOM header and 2 extension = php_gd2.dll is not enabled (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?


Reply to discussion (solution)

Isn't it clear? You can correct the five mistakes.

Should the page you want to open be the page that generates the verification code? Otherwise, what if you enable error display?

It has nothing to do with, that is warning information, and it has nothing to do with the verification code. The other is to use it error_reporting (E_ALL &~ E_NOTICE); the verification code is not displayed.

Paste your code!

I don't know if you're going to fix the problem, or are you kidding me?

I suggest you leave my post if you do not like my questions. The world is very large and you are interested in many places, no matter what you are, how much do you give me to tease you? You just gave me money and I still want to play with you!

I don't expect anyone to answer my questions, but I don't expect anyone to be interested in my questions! Have fun. you don't look in the mirror. Who are you! Are you qualified for this?

Paste your code!

I don't know if you're going to fix the problem, or are you kidding me?


From the perspective of your many reply methods, we can tell that you are a three or four Stream role in php, and there are many strange problems you cannot solve, don't think that the problem you think is very simple is not a problem. you are far away! A real expert, you see a face like you, you are at best a person familiar with php, I am also, but I am not the same, I am very modest.

Different situations are analyzed.
Your verification code picture is not displayed, and the above notice and warning are warnings and prompts of login. php, which has nothing to do with the verification code.
Can you paste the code that generates the verification code Image for analysis.

Different situations are analyzed.
Your verification code picture is not displayed, and the above notice and warning are warnings and prompts of login. php, which has nothing to do with the verification code.
Can you paste the code that generates the verification code Image for analysis.


That's right. notice and warning are a warning in php Usage that does not affect code running. this is common knowledge that anyone who just learned php knows.
Also, my problem is actually the verification code in the verification class. At first I thought it was a BOM header problem, but it was not possible to save it as a BOM header. In addition, this code is an example in the tutorial. it can be displayed in the Speaker's environment. of course, he uses a low php version. I am a little higher, but the high compatibility is low.
In addition, GD has also been enabled, and Baidu has not implemented many methods. That's why I posted this post. There are a lot of code, so I guess you are not in the mood.
There is also a php page for the verification code, but I have read the code.

Verification code

 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 the 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 the 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 ), $ this-> height/1.4, $ this-> fontcolor, $ this-> font, $ this-> code [$ I]);} // Generate the line and snowflake 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 <100; $ I ++) {$ color = imagecolorallocate ($ this-> img, mt_rand (200,255 ), mt_rand (200,255), mt_rand (200,255); imagestring ($ this-> img, mt_rand (), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), '*', $ color) ;}// outPut private function outPut () {header ('content-type: image/png '); imagepng ($ this-> img); imagedestroy ($ this-> img);} // generate public function doimg () {$ this-> createBg (); $ this-> createCode (); $ this-> createLine (); $ this-> createFont (); $ this-> outPut ();} // Obtain the verification code public function getCode () {return strtolower ($ this-> code );}}

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 class define ('root _ path', dirname (_ FILE _); // verification code class ValidateCode {private $ charset = 'hangzhou '; // random factor private $ code; // verification code private $ codelen = 4; // verification code length private $ width = 130; // width private $ height = 50; // height private $ img; // graphic resource handle private $ font; // The specified font private $ fontsize = 20; // specify the font size private $ fontcolor; // specify the font color // Constructor initializes 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 the 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 the 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 ), $ this-> height/1.4, $ this-> fontcolor, $ this-> font, $ this-> code [$ I]);} // Generate the line and snowflake 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 <100; $ I ++) {$ color = imagecolorallocate ($ this-> img, mt_rand (200,255 ), mt_rand (200,255), mt_rand (200,255); imagestring ($ this-> img, mt_rand (), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), '*', $ color) ;}// outPut private function outPut () {header ('content-type: image/png '); imagepng ($ this-> img); imagedestroy ($ this-> img);} // generate public function doimg () {$ this-> createBg (); $ this-> createCode (); $ this-> createLine (); $ this-> createFont (); $ this-> outPut ();} // Obtain the verification code public function getCode () {return strtolower ($ this-> code) ;}}$ obj = new ValidateCode (); $ obj-> doimg ();


I understand. I didn't put the source code under the root directory. thank you for your great skill.

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.