分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

PHP学习笔记-简单的面向过程写的验证码

发布时间:2023-09-06 01:16责任编辑:蔡小小关键词:PHP验证码
<?php/** * Created by PhpStorm. * User: Administrator * Date: 2017\10\10 0010 * Time: 19:44 */ //生成随机验证码$strNumber = join(‘‘,range(0,9));$strChar   = join(‘‘,range(‘a‘,‘z‘));$str = $strNumber.$strChar.strtoupper($strChar);$str = substr(str_shuffle($str),‘0‘,4);header("Content-type: image/png");//创建画布$width = 100;$height = 50;$image = imagecreate($width,$height);//创建颜色$bgcolor  = imagecolorallocate($image,rand(0,20),rand(0,20),rand(0,20));//备用颜色(干扰线)$colorone = imagecolorallocate($image,rand(100,155),rand(200,155),rand(100,155));;//干扰线for($j=0; $j<10; $j++){    imageline($image, rand(0,$width), rand(0,$height-20), rand(0,$width), rand(0,$height), $colorone);}//循环添加字符到画布   每个字符的坐标为(总宽度 / 验证码的个数)for($i=0; $i<4; $i++){    //备用颜色(文字)    $fontcolor= imagecolorallocate($image,rand(0,255),rand(100,200),rand(180,255));    $x = (($width / 4) * $i) + $width / 10;    $y = rand(10,$height-20);    imagechar($image, 5, $x, $y,$str[$i], $fontcolor);}imagepng($image);imagedestroy($image);


650) this.width=650;" src="https://s1.51cto.com/wyfs02/M02/A6/DF/wKioL1ncy2CR3-aSAABGfWyFtBc245.png-wh_500x0-wm_3-wmp_4-s_998014518.png" style="float:none;" title="QQ截图20171010213942.png" alt="wKioL1ncy2CR3-aSAABGfWyFtBc245.png-wh_50" />

650) this.width=650;" src="https://s1.51cto.com/wyfs02/M01/08/2D/wKiom1ndOm7TzOYXAABgH-WuCgM475.png-wh_500x0-wm_3-wmp_4-s_1187110826.png" style="float:none;" title="QQ截图20171010213947.png" alt="wKiom1ndOm7TzOYXAABgH-WuCgM475.png-wh_50" />


本文出自 “YBT-PHP” 博客,请务必保留此出处http://ybtphp.blog.51cto.com/13257319/1971297

PHP学习笔记-简单的面向过程写的验证码

原文地址:http://ybtphp.blog.51cto.com/13257319/1971297

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved