php显示随机验证码
1 <?php 2 header("Content-Type:image/png"); 3 // $str="北京欢迎你!"; 4 // imagefill($img,0,0,$color1); 5 // // imagestring($img,5,0,0,$str,$color2); 6 7 //1.产生随机字符串 8 $arr1 = array_merge(range('A','Z'),range(0,9),range('a','z')); 9 shuffle($arr1); 10 $arr2 = array_rand($arr1,4); 11 $str = ""; 12 // print_r($arr2); 13 // echo "<br/>"; 14 foreach($arr2 as $index){ 15 $str .= $arr1[$index]; 16 } 17 // echo $str; 18 // 2.创建空画布 19 $width = 200; 20 $height = 100; 21 22 $img = imagecreatetruecolor($width,$height); 23 // 3.绘制带填充矩形 24 $color1 = imagecolorallocate($img,mt_rand(80,255),mt_rand(100,255),mt_rand(180,255)); 25 $color2 = imagecolorallocate($img,255,0,0); 26 imagefilledrectangle($img,0,0,$width,$height,$color1); 27 // 4.绘制像素点 28 for ($i=0; $i <100; $i++) { 29 $color3=imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); 30 imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$color3); 31 } 32 $fontfile="F:\phpStudy\WWW\myweb\FZXBSJW.ttf"; 33 imagettftext($img,24,0,60,60,$color2,$fontfile,$str); 34 imagepng($img); 35 imagedestroy($img);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)