Perfect solution to TP verification code does not display

【Foreword】

      I just encountered it, and I can see that other people's operations can be displayed normally, but mine only shows a black screen. . .

     The reason will be queried later. There cannot be any output before the picture is output.

 

【main body】

The solution is as follows:

Do not show captcha codes:

 

public function verify(){  
                $verify = new \Think\Verify();  
                $verify->entry();  
        }

 

 

Solution: add ob_clean()

 

public function verify(){  
                ob_clean();  
                $verify = new \Think\Verify();  
                $verify->entry();  
        }  

 Refresh the page again to display it.

 

 

Reason analysis:

      There may be the following situations

1. First make sure whether the gd library is enabled

2. Whether there is a bom header on the page

3. Whether the imported ORG.Util.Image exists

4. Whether there is define('APP_DEBUG', TRUE) in the entry file; //Whether the debug mode is enabled, please change it to false when going online

     

After the analysis here is the second type, there is a Bom header. Share here what is a Bom head

What is a Bom head 

BOM: Byte Order Mark 
UTF-8 BOM is also called UTF-8 signature . In fact, UTF-8 BOM has no effect on UFT-8. It is BOM added to support UTF-16 and UTF-32. The meaning of BOM signature is Tell the editor what encoding the current file uses, which is convenient for the editor to identify, but although the BOM is not displayed in the editor, it will generate output, just like an extra blank line.

If it happens after you modify any PHP file:

* Can't log in or log out; * A blank appears at the top of the page; * An error warning appears at the top of the page; * Other abnormal conditions.

It's mostly an editor problem.

This program uses UTF-8 encoding. Almost all text editing software nowadays can display and edit UTF-8 encoded files. But unfortunately, many of them don't perform well.

Similar to the Notepad and other software that comes with WINDOWS, when saving a file encoded in UTF-8, three invisible characters (0xEF 0xBB 0xBF, or BOM) will be inserted at the beginning of the file. It is a hidden string of characters used to let editors such as Notepad recognize whether the file is encoded in UTF-8. For normal files, this shouldn't cause any trouble. But for PHP, BOM is a big hassle.

PHP does not ignore the BOM, so when reading, including, or referencing these files, the BOM is included as part of the text at the beginning of the file. According to the characteristics of the embedded language, this string of characters will be executed (displayed) directly. As a result, even if the top padding of the page is set to 0, it is impossible to make the entire web page close to the top of the browser, because there are these 3 characters at the beginning of html!

The biggest trouble is not this. Restricted by the cookie sending mechanism, in the files that already have BOM at the beginning of these files, cookies cannot be sent (because PHP has already sent the file header before cookies are sent), so the login and logout functions are invalid. All functions that rely on COOKIE and SESSION are invalid.

Therefore, when editing or changing any text file, be sure to use an editor that does not add BOMs. Editors under Linux should not have this problem. Under WINDOWS, do not use editors such as Notepad. The recommended editors are: Editplus 2.12 or later; EmEditor; UltraEdit (need to cancel the 'Add BOM' related option); Dreamweaver (need to cancel the 'Add BOM' related option) and so on.

For a file that has already added a BOM, if you want to cancel it, you can use the above editor to save it once. (Editplus needs to be saved as gb first, and then as UTF-8 .), the following is the program solution:

 

 

1. Directly use this blog's simple method to remove BOM

2.  Use ultraedit to remove the bom header method: After opening the file, select the encoding format of the save as option (utf-8 without bom header), and confirm it is ok

 

 

 

 

 

.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326127792&siteId=291194637