时间:2019-12-05 浏览量:

php创建图像验证码源码:
<?php
/**
* 图像验证码
* 1、生成验证码字符串
* 2、创建画布大小,填充颜色
* 3、创建杂色到画布
* 4、创建干扰线到画布
* 5、创建字符串到画布上
* 6、输出图像
*/
//0-9 a-z A-Z
$arr = array_merge(range(0,9),range('a','z'),range('A','Z'));
//打乱数组
shuffle($arr);
//从数组中从下标0开始,取出4个元素
$arrlen = array_splice($arr,0,4);
//将数组转成字符串
$text = implode($arrlen);
//创建画布
$width = 120;
$height = 40;
$image = imagecreatetruecolor($width, $height);
$reccolor = imagecolorallocate($image,mt_rand(130,255),mt_rand(130,255),mt_rand(130,255));
imagefilledrectangle($image,0,0,$width,$height,$reccolor);
//添加杂色到画布
for ($i=1;$i<=450;$i++)
{
$pixcolor = imagecolorallocate($image,mt_rand(60,160),mt_rand(60,160),mt_rand(60,160));
imagesetpixel($image,mt_rand(0,$width),mt_rand(0,$height), $pixcolor);
}
//将字符串写到画布
$ttfpath = dirname(__FILE__).'/arial.ttf';
$ttfcolor = imagecolorallocate($image,mt_rand(0,120),mt_rand(0,120),mt_rand(0,120));
imagettftext($image,32,0,5,35, $ttfcolor, $ttfpath, $text);
//创建干扰线到画布
for ($i=1;$i<=15;$i++)
{
$linecolor = imagecolorallocate($image,mt_rand(30,150),mt_rand(30,150),mt_rand(30,150));
imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$linecolor);
}
//输出图像
header("Content-Type:image/png");
imagepng($image);
imagedestroy($image);RELATED RECOMMEND
2019-12-05
针对不同云服务器、虚拟主机,运行PHP的环境也有所不同,目前主要分为:Nginx、apache、IIS以及其他服务器。此文给大家分享如何隐藏ThinkPhp 伪静态URL中的index.php。【Nginx服务器】在原有的nginx重写文件里新增以下代码片段:location / {if (!-e $request_filename) {rewrite ^(.*)$ /in

2019-12-05
ThinkPhp多文件上传1、模板页面中代码<form action="{:url('uploads')}" method="post" enctype="multipart/form-data"><p>File:<input type="fi

2019-12-05
一、缓存的作用减少数据库压力用户交互比较少二、TP对缓存的支持支持缓存类型包括file,memcache,wincache,sqlite,redis和xcache三、缓存设置(application\config.php) 'cache'=> [// 驱动方式'type'=> 'File',

Copyright © 2012-2025世敏网络 版权所有 闽ICP备18026760号-1
闽公网安备 35020502000640号 网站地图 Sitemap 关键词聚合

