RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
PHP用GD库绘制图片,制作验证码浏览器不能输出

1,代码如下:

目前创新互联公司已为上千家的企业提供了网站建设、域名、网页空间、网站运营、企业网站设计、揭东网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

function fillRandomString(){

//生成验证码

$char = array_merge(range(0, 9),range("a", "z"),range("A", "Z"));

//讲字符串$char打乱

$luan = str_shuffle(implode("", $char));

//从字符串中随机取四位

return  substr($luan, 0,4 );

}

//创建画布

header('content-type:p_w_picpath/png');

$height = 20;

$width = 80;

$p_w_picpath = p_w_picpathcreate($width, $height);

$black = p_w_picpathcolorallocate($p_w_picpath, 0, 0, 0);

$white = p_w_picpathcolorallocate($p_w_picpath, 255, 255, 255);

//画图片矩形

p_w_picpathfilledrectangle($p_w_picpath, 1, 1, $width-2, $height-2, $white);

//填充字符串

p_w_picpathstring($p_w_picpath, 20, 20,  4, fillRandomString(), $black);

        //输出图片

p_w_picpathpng($p_w_picpath);

 

//销毁图片

p_w_picpathdestroy($p_w_picpath);

但是在浏览器上输出显示不了,原因是在向浏览器输出之前没有清理缓存

在header()之前加入代码 ob_clean();即可


本文标题:PHP用GD库绘制图片,制作验证码浏览器不能输出
文章位置:http://scyingshan.cn/article/piddso.html