一个验证码程序

setail 2011-08-02 02:59:09
一个验证码程序,下面的程序运行起来总是说图像因其本身原因无法显示,如果去掉$identifyingCode .= $authnum;图像就能显示出来了,为啥呢?还有,imagefill我看他加不加都没啥影响啊,是不是没啥用啊?


session_start();
//生成验证码图片

$im = imagecreate(50,18);
$back = ImageColorAllocate($im, 245,245,245);
imagefill($im,0,0,$back);
for($i=0;$i<4;$i++){
$fontColor = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
$authnum=chr(mt_rand(48,57));

imagestring($im, mt_rand(1, 5), 2+$i*10, 1, $authnum, $fontColor);
$identifyingCode .= $authnum;
}
...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ohmygirl 2011-08-02
  • 打赏
  • 举报
回复
生成验证码之前先初始化$identifyingCode

$identifyingCode ='';


header("content-type:image/gif");
session_start();
$identifyingCode ='';
//生成验证码图片

$im = imagecreate(50,18);
$back = ImageColorAllocate($im, 245,245,245);
imagefill($im,0,0,$back);
for($i=0;$i<4;$i++){
$fontColor = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
$authnum=chr(mt_rand(48,57));

imagestring($im, mt_rand(1, 5), 2+$i*10, 1, $authnum, $fontColor);
$identifyingCode .= $authnum;
}
$_session['code']=$identifyingCode;//你的代码中也没有把验证码加入session
setail 2011-08-02
  • 打赏
  • 举报
回复
验证码,要存到session里面的。。。
[Quote=引用 1 楼 xuzuning 的回复:]
$identifyingCode 是什么,在哪定义的?
[/Quote]
xuzuning 2011-08-02
  • 打赏
  • 举报
回复
$identifyingCode 是什么,在哪定义的?

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧