从PHP5.2.6升级PHP5.3.1,验证码程序出错了。

源程序如下:

 

@header("Content-Type:image/png");
session_start();
$_SESSION['authnum'] = '';

$str = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; 
$list = explode(",", $str);
for($i=0; $i<4; $i++){
	$randnum = rand(0, 62);
	$authnum .= $list[$randnum];
}
$_SESSION['authnum'] = strtolower($authnum);

$im = @imagecreate(40, 20) or die("Cant's initialize new GD image stream!");
$text_color = imagecolorallocate($im, 255, 255, 255); //文本顔色
$background_color01 = imagecolorallocate($im, 255, 0, 0); //背景色1
$background_color02 = imagecolorallocatealpha($im, 255, 255, 255, 127); //背景色2
$noise_color = imagecolorallocate($im, 200, 200, 200); //干扰顔色
imagefill($im, 0, 0, $background_color02); //区域填充

imagestring($im, 5, 2, 2, $authnum, $text_color);
/*for($i=0; $i<400; $i++){ //加入干扰象素 
	imagesetpixel($im, rand()%90 , rand()%30 , $noise_color);
}*/
imagepng($im);
imagedestroy($im);

 

 

注释掉@header("Content-Type:image/png");,单独运行程序,发现错误:

 

Notice: Undefined variable: authnum in D:\WAMP\wwwroot\mei-de\admin\authnum.php on line 10

报错说是未定义变量authnum,之前用的是PHP5.2.6同样的程序也未有报错,怪哉。

 

在程序前定义好authnum变量好,程序OK。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值