Every time we log in to the website, we are always asked to fill in a random verification code. Have you ever thought about how it is implemented? This article will introduce a code that uses PHP language to draw a random verification code, which has certain reference significance. Come and learn it quickly!
<?php //使用PHP绘图技术,画出自己的验证码 $checkCode=""; for($i=0;$i<4;$i++){ //dechex把一个十进制数转换成十六进制 $checkCode.=dechex(rand(1,15)); } //存入到session session_start(); $_SESSION['checkcode']=$checkCode; //创建画布 $image1=imagecreatetruecolor(110,30); //创建颜色 $white=imagecolorallocate($image1,255,255,255); //绘制字符 imagestring($image1,rand(1,5),rand(0,80),rand(0,20),$checkCode,$white); //画出干扰线 //创建干扰线随机颜色 for($i=0;$i<20;$i++){ $randomColor=imagecolorallocate($image1,rand(0,255),rand(0,255),rand(0,255)); imageline($image1,rand(0,110),rand(0,30),rand(0,110),rand(0,30),$randomColor); } //输出 header("content-type:image/png"); imagepng($image1); //销毁图片 imagedestroy($image1); ?>
The picture format is like this
Related tutorials: PHP video tutorial
The above is the detailed content of How to draw various character verification codes using PHP language. For more information, please follow other related articles on the PHP Chinese website!