欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP图片验证码制作(中)_PHP教程

程序员文章站 2022-03-29 21:10:46
...
随机生成数字,字母的代码:

//che.php
session_start();
for($i=0;$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 {
$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 {
imagesetpixel($im,rand(0,40),rand(0,20),$cg);
}
把文字写入图片代码:

$str=array('我','我','亲','亲');//存储显示的汉字
for($i=0;$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.bkjia.comtruehttp://www.bkjia.com/PHPjc/478237.htmlTechArticle随机生成数字,字母的代码: ?php //che.php session_start(); for($i=0;$i4;$i++) { $rand.=dechex(rand(1,15)); } $_SESSION[check_num]=$rand; $image=imagecreatetruecolor(50...