分享web开发知识

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

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

php验证码

发布时间:2023-09-06 02:28责任编辑:赖小花关键词:验证码
先创建一个demo.php;<img src="imgcode.php" onclick="this.src = ‘imgcode.php?num=‘+new Date().getTime();" />然后创建一个imgcode.php<?phpfunction get_rand_str($length = 4){ ???$chars = ‘123456789ABCDEFGHJKLMNPQRSTUVWXYZ‘; ???$str = str_shuffle($chars); // 随机打乱一个字符串 ???$str = substr($str,0,$length); ???$str = strtolower($str); ???return $str;}//验证码图片宽度和高度$width = 45;$height = 18;//新建一张彩色图片$img = imagecreatetruecolor($width,$height);//给这张图片新建两个颜色 //背景颜色$backgroundcolor = imagecolorallocate($img,74,147,223);//文字颜色$textcolor = imagecolorallocate($img,255,255,255);//画一矩形并填充 ??$width,$height, 对角线imagefilledrectangle($img,0,0,$width,$height,$backgroundcolor);//获取随机数$get_code = get_rand_str(); //获取出来的随机数写到图片上面imagestring($img,5,6,1,$get_code,$textcolor);//防止别人恶意刷验证码在图片上面添加一些点for($i=0;$i<=20;$i++){ ???$x = mt_rand(0,$width); ???$y = mt_rand(0,$height); ???$pxColor = imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); ???imagesetpixel($img,$x,$y,$pxColor);}//写一个输出图片的声明头信息header("Content-Type:image/png");imagepng($img);//输出完成后销毁imagedestroy($img);?>

php验证码

原文地址:https://www.cnblogs.com/qixidi/p/10202482.html

知识推荐

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