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

PHP验证码 @符号

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:30:13
Original
1115 people have browsed it

求助 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));//前面的这个@符号要是不加,图片就显示不出来。
    }    
    @$_SESSION[check_pic]=$rand; //前面的@符号要是去掉的话这个就会报错 而且全是乱码。 
    $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);
?>

Copy after login



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 "验证码错误";
            
        }
        
    }
?>
Copy after login
  PHP验证码 @符号
验证码:


我现在前面要是不加@符号的话就是报错。下面是错误的提示
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

加上@符号之后就一切正常了 这是什么错误


------解决方案--------------------
加引号 $_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>
Copy after login
PHP code
    session_start();
    $rand = '';
    for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
PHP code

session_start();

for($i=0;$i @$rand.=dechex(rand(1,15));//前面的这个@符号要是不加,图片就显示不出来。
}
@$_SESSION[check_pic]=$rand; //前面的@符号要是去掉的话这个就会报错 而且全是乱码。 ……
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template