Home >Backend Development >PHP Tutorial > PHP验证码 @符号

PHP验证码 @符号

WBOY
WBOYOriginal
2016-06-13 10:24:371280browse

求助 PHP验证码 @符号

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php session_start();        for($i=0;$i<4;$i++){        @$rand.=dechex(rand(1,15));[email&#160;protected],图片就显示不出来。    }        @$_SESSION[check_pic]=$rand; [email&#160;protected] 而且全是乱码。     $im=imagecreatetruecolor(100,30);         $bg=imagecolorallocate($im,0,0,0);    $te=imagecolorallocate($im,255,255,255);    imagestring($im,5,0,0,$rand,$te);      header("content-type:image/jpeg");  imagejpeg($im);?>



PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php session_start();    if($_POST[code]){        if($_POST[code]==$_SESSION[check_pic]){                echo "验证码正确:".$_SESSION[check_pic];        }            else         {                echo "验证码错误";                    }            }?>
 PHP验证码 @符号
验证码:


[email protected]??误的提示
Notice: Use of undefined constant code - assumed 'code' in F:\wamp\apps\project\code_sub.php on line 3

Notice: Use of undefined constant code - assumed 'code' in F:\wamp\apps\project\code_sub.php on line 4

Notice: Use of undefined constant check_pic - assumed 'check_pic' in F:\wamp\apps\project\code_sub.php on line 4

[email protected] 这是什么错误


------解决方案--------------------
加引号 $_SESSION["check_pic"]

undefined constant是未定义常量的意思,不加引号字串按常量看待
------解决方案--------------------
PHP code
for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>$rand.=<br><br>这个变量无赋值的情况使用,所以导致notice错误,图像是二进制,notice是文本,二者混合自然导致图片无法显示。<br><br>解决办法:<br>先给$rand赋值<br><br>$rand='';<br><br><br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
    session_start();    $rand = '';    for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>
探讨
PHP code

session_start();

for($i=0;$i @$rand.=dechex(rand(1,15));[email protected],图片就显示不出来。
}
@$_SESSION[check_pic]=$rand; [email protected] 而且全是乱码。 ……
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