Heim  >  Artikel  >  Backend-Entwicklung  >  PHP验证码图片不能输出,该如何解决

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

WBOY
WBOYOriginal
2016-06-13 13:23:09870Durchsuche

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
<?php function _code(){
//运行验证码
}
?>
<br><font color="#e78608">------解决方案-------------------- <div class="clear">
                 
              
              
        
            </div></font>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn