include '../../lib/functions.php';if(!isset($SESSION))
{
session_start();
}$r=null;
for($i=0;$i<4;$i++)
{
$r.=dechex(rand(1,15));
}
$SESSION['check_pic']=$r;//随机数存储在session中
$img=imagecreatetruecolor(100,40)or die("建立图片失败");
$bg=imagecolorallocate($img,0,0,0);//第一次使用创建的是背景颜色$cl=imagecolorallocate($img,rand(1,250),rand(1,250),rand(1,254));//$img ,red,blue,grenn
imagestring($img,5,rand(0,40),rand(0,20),$r,$cl);//$img,font,x,y,string,colorheader("content-type:image/jpeg");//页面输出为一个图片格式
imagejpeg($img);// 以 filename 为文件名创建一个 JPEG 图像。
imagedestroy($img);验证码输出代码:为啥一加第一行include代码,图片就不显示了。functions.php显示一组随机字符串。
header("content-type:image/jpeg")前难道不能加include语句?
{
session_start();
}$r=null;
for($i=0;$i<4;$i++)
{
$r.=dechex(rand(1,15));
}
$SESSION['check_pic']=$r;//随机数存储在session中
$img=imagecreatetruecolor(100,40)or die("建立图片失败");
$bg=imagecolorallocate($img,0,0,0);//第一次使用创建的是背景颜色$cl=imagecolorallocate($img,rand(1,250),rand(1,250),rand(1,254));//$img ,red,blue,grenn
imagestring($img,5,rand(0,40),rand(0,20),$r,$cl);//$img,font,x,y,string,colorheader("content-type:image/jpeg");//页面输出为一个图片格式
imagejpeg($img);// 以 filename 为文件名创建一个 JPEG 图像。
imagedestroy($img);验证码输出代码:为啥一加第一行include代码,图片就不显示了。functions.php显示一组随机字符串。
header("content-type:image/jpeg")前难道不能加include语句?
解决方案 »
- php 为什么喜欢用 thread-xxx-xx.php 为名?
- 请问Zend Studio如何查找字符串?
- 为何用mysqli类时foreach只能取出一行,而while循环取出多行数据?
- linux下 antiword获取word 文件问题
- 如何套用两个while循环
- mail()发送的邮件的标题是乱码,正文的编码是正常的?
- 我受打击了,为什么他们能生成带中文的图片,难道真的和服务器速度有关??
- 请教有没有PHP能直接读excel文件的方法(非另存为其它格式)?
- 怎样使一行内容,显示不完用....代替!
- 简单的图形计数器问题
- 网站消息系统数据表结构设计求助
- 小菜求帮助!一个运算符执行顺序问题
这个是functions.php的代码:
function random_text($count,$rm_similar=false)//$count 取的位数,$rm_similar 是否调用unset函数
{
$chars= array_flip(array_merge(range(0,9),range('a','z')));
//range 创建并返回一个包含指定范围的元素的数组,array_flip反转数组,array_merge()把两个数组合并为一个数组
if($rm_similar)
{
unset($chars[0],$chars[1],$chars[2],$chars[5],$chars[8],$chars['b'],$chars['i'],$chars['o'],$chars['q'],
$chars['s'],$chars['u'],$chars['v'],$chars['z']);
//unset 删除数组中指定的数据
}
$text='';
for($i=0;$i<$count;$i++)
{
$text.=array_rand($chars);//从数组中随机选出一个或多个元素,并返回
}
return $text;
}