- PHP code
<?php session_start(); for($i=0;$i<4;$i++){ @$rand.=dechex(rand(1,15));[email protected],图片就显示不出来。 } @$_SESSION[check_pic]=$rand; [email 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
<?php session_start(); if($_POST[code]){ if($_POST[code]==$_SESSION[check_pic]){ echo "验证码正确:".$_SESSION[check_pic]; } else { echo "验证码错误"; } }?><form action="" method="post"><img src="code.php"><br>验证码:<input type="text" name="code"><input type="submit" value="提交"></form>
[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<4;$i++){ $rand = ''; $rand.=dechex(rand(1,15));[email protected],图片就显示不出来。 } $_SESSION['check_pic']=$rand; [email protected] 而且全是乱码。
------解决方案--------------------
$rand.=
这个变量无赋值的情况使用,所以导致notice错误,图像是二进制,notice是文本,二者混合自然导致图片无法显示。
解决办法:
先给$rand赋值
$rand='';
------解决方案--------------------
- PHP code
session_start(); $rand = ''; for($i=0;$i<4;$i++){ $rand.=dechex(rand(1,15));[email protected],图片就显示不出来。 } $_SESSION['check_pic']=$rand; [email 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);
------解决方案--------------------