PHP头条
热点:

PHP图片验证码制作(中)


随机生成数字,字母的代码:
 
<?php
//che.php
session_start();
for($i=0;$i<4;$i++)
 {
 $rand.=dechex(rand(1,15));
 }
 $_SESSION['check_num']=$rand;
$image=imagecreatetruecolor(50,30);
$bg=imagecolorallocate($im,0,0,0);//第一次用调色板的时候,背景颜色
$te=imagecolorallocate($im,255,255,255);
imagestring($image,6,rand(0,20),rand(0,2),$rand,$te);
ob_clean();//PHP网页中因为 要生成验证码而出现 图像"http://localhost/**.php"因其本身有错无法显示
header("Content-type:image/jpeg"); imagejpeg($image);
?>
 
给图片画出干扰线代码:
for($i=0;$i<8;$i++)//画出多条线
{
$cg=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//产生随机的颜色
imageline($im,rand(10,40),0,rand(10,40),20,$cg);
}
给图片画出干扰点的代码:
for($i=0;$i<80;$i++)//画出多个点
{
imagesetpixel($im,rand(0,40),rand(0,20),$cg);
}
把文字写入图片代码:
 
$str=array('我','我','亲','亲');//存储显示的汉字
for($i=0;$i<4;$i++)
{
     $sss.=$str[rand(0,3)];//随机显示汉字
}

//$str=iconv("gb2312","utf-8",$str); //汉字编码转化,我的好像不需要
imagettftext($im,10,0,rand(5,60),rand(5,60),$te,"simhei.ttf",$sss);//
 
0:字体的倾斜度,“simhei.ttf”:字体样式,一般放在根目录下;

 

 

摘自 ms.元

www.phpzy.comtrue/phprm/16878.htmlTechArticlePHP图片验证码制作(中) 随机生成数字,字母的代码: ?php //che.php session_start(); for($i=0;$i4;$i++) { $rand.=dechex(rand(1,15)); } $_SESSION[check_num]=$rand; $image=imagecreatetruecolor(50,30); $bg=imagecoloralloca...

相关文章

    暂无相关文章

PHP之友评论

今天推荐