PHP校验码生成--备忘
<?php session_start();//保存生成值,以与用户输入比较 //------------------------------------------------------------------------- $img_w = 80;// 设置图片宽 $img_h = 20;// 设置图片高 $pixel_num = 200;//点越多干扰越大 $is_set_line = true;// 启用干扰线 $pixel_mode = 2;// 干扰点模式,1,同色;2,杂色 //------------------------------------------------------------------------- // 随机数产生器 function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } mt_srand(make_seed());//4.2.0以下版本适用 $authnum = mt_rand(100, 99999); // 加入session $_SESSION['verifycode']=$authnum; //echo $authnum; //生成验证码图片 Header("Content-type: image/PNG"); $im = imagecreatetruecolor($img_w, $img_h); $bg_color = ImageColorAllocate($im, mt_rand(250,255),mt_rand(250,255),mt_rand(250,255)); // 绘制背景 imagefill($im,0,0,$bg_color); $total_width = 0; $word_info = array(); // 循环,获取文字信息 $word_length = strlen($authnum); for($ii=0; $ii<$word_length; $ii++) { $word_space = mt_rand(1,5); $font = rand(3,5); mt_rand(1,9)%2 == 0?$top = 1:$top = 3; $word_info[$ii]['char'] = substr($authnum,$ii,1); $word_info[$ii]['font'] = $font; $word_info[$ii]['offset'] = $top; if($ii == 0) { $word_info[$ii]['width'] = 0; } $word_info[$ii]['width'] = imageFontWidth($font)+$word_space; $word_info[$ii]['height'] = imageFontHeight($font); $word_info[$ii]['color'] = imageColorAllocate($im, mt_rand(0,50),mt_rand(0,150),mt_rand(0,200)); // 文字总宽度 $total_width += $word_info[$ii]['width']; // 取第一个字体的高度 if($ii == 0) { $total_height = imagefontHeight($font); } } // 计算偏移 $offset_x = floor(($img_w - $total_width)/2); $offset_y = floor(($img_h - $total_height)/2); // 填充验证码 $wid = 0; $i = 0; foreach($word_info as $key=>$val) { if($i>0) { $wid += $val['width']; } imagestring($im, $val['font'], $offset_x + $wid, $val['offset'] + $offset_y, $val['char'], $val['color']); $i++; } switch($pixel_mode) { case 1: $pixel_color = ImageColorAllocate($im, mt_rand(50,255), mt_rand(50,255), mt_rand(50,255)); // 干扰象素 for($i=0;$i<$pixel_num;$i++) { imagesetpixel($im, mt_rand()%$img_w , mt_rand()%$img_h , $pixel_color); } break; case '2': // 干扰象素 for ($i=0;$i<=128;$i++) { $pixel_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255)); imagesetpixel($im,mt_rand(2,128),mt_rand(2,38),$pixel_color); } break; default: $pixel_color = ImageColorAllocate($im, mt_rand(50,255), mt_rand(50,255), mt_rand(50,255)); // 干扰象素 for($i=0;$i<$pixel_num;$i++) { imagesetpixel($im, mt_rand()%$img_w , mt_rand()%$img_h , $pixel_color); } break; } ImagePNG($im); ?>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

JWT是一种基于JSON的开放标准,用于在各方之间安全地传输信息,主要用于身份验证和信息交换。1.JWT由Header、Payload和Signature三部分组成。2.JWT的工作原理包括生成JWT、验证JWT和解析Payload三个步骤。3.在PHP中使用JWT进行身份验证时,可以生成和验证JWT,并在高级用法中包含用户角色和权限信息。4.常见错误包括签名验证失败、令牌过期和Payload过大,调试技巧包括使用调试工具和日志记录。5.性能优化和最佳实践包括使用合适的签名算法、合理设置有效期、

SOLID原则在PHP开发中的应用包括:1.单一职责原则(SRP):每个类只负责一个功能。2.开闭原则(OCP):通过扩展而非修改实现变化。3.里氏替换原则(LSP):子类可替换基类而不影响程序正确性。4.接口隔离原则(ISP):使用细粒度接口避免依赖不使用的方法。5.依赖倒置原则(DIP):高低层次模块都依赖于抽象,通过依赖注入实现。

如何在系统重启后自动设置unixsocket的权限每次系统重启后,我们都需要执行以下命令来修改unixsocket的权限:sudo...

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸

使用PHP的cURL库发送JSON数据在PHP开发中,经常需要与外部API进行交互,其中一种常见的方式是使用cURL库发送POST�...
