Home  >  Article  >  Backend Development  >  PHP验证码图片不能输出,该如何解决

PHP验证码图片不能输出,该如何解决

WBOY
WBOYOriginal
2016-06-13 10:33:03786browse

PHP验证码图片不能输出
文件名 global_func.php

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function _code(){//运行验证码    //随记码个数    $_rnd_code=4;    for($i=0;$i


这个我要是调用 global_func.php 这个文件下的 function _code(); 就出错是一个红叉。
code.php
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->_code();



这个是我直接写在code.php中就能够使用。
code.php
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    //随记码个数    $_rnd_code=4;    for($i=0;$i



这段验证码我直接运行不封装成函数的形式可以使用验证码一切正常。
但是我用function _code() 之后 在调用 _code() 在html中显示的是一个红叉。不知道是为什么


------解决方案--------------------
会不会是 header('Content-Type:image/png'); 的原因,
BOM头会影响到浏览器预期的文件类型
------解决方案--------------------
即使是写成函数,调用也是没有问题的。

PHP code
<?phpfunction _code(){//运行验证码}?><br><font color="#e78608">------解决方案--------------------<div class="clear">
                 
              
              
        
            </div></font>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn