<?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);
?>
<?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>
我现在前面要是不加@符号的话就是报错。下面是错误的提示
Notice: Use of undefined constant code - assumed 'code' in F:\wamp\apps\project\code_sub.php on line 3Notice: Use of undefined constant code - assumed 'code' in F:\wamp\apps\project\code_sub.php on line 4Notice: Use of undefined constant check_pic - assumed 'check_pic' in F:\wamp\apps\project\code_sub.php on line 4加上@符号之后就一切正常了 这是什么错误
$rand = '';
$rand.=dechex(rand(1,15));//前面的这个@符号要是不加,图片就显示不出来。
}
$_SESSION['check_pic']=$rand; //前面的@符号要是去掉的话这个就会报错 而且全是乱码。
if($_POST['code']){
if($_POST['code']==$_SESSION['check_pic']){
echo "验证码正确:".$_SESSION['check_pic'];
}
先给$rand赋值$rand='';
$rand = '';
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);
错误一:$rand.=处,原型既:$rand = $rand + ,未先定义变量$rand,所以报notice错误;
错误二:@$_SESSION[check_pic]=$rand,check_pic是数组$_SESSION的键名,但是你这里没有使用引号引住键名,就把check_pic当成了一个常量,而你又没有定义常量”check_pic“,在使用未定的常量时,常量的值==常量名
<?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>改完之后 Notice: Undefined index: code in F:\wamp\apps\project\code_sub.php on line 3
提示错误if($_POST['code']) 有错么。
if ($_POST && $_POST['code']) {
...
}
http://www.okbase.net/doc/details/69