php完整验证码代码
<?php
require_once 'string.func.php';
//通过GD库做验证码
/**
*添加验证文字
* @param int $type
* @param int $length
*/
function buildRandomString($type=1,$length=4){
$row='';
if($type==1){
$row=join('',range(0, 9));
}else if($type==2){
$row=join('', array_merge(range('a','z'),range('A', 'Z')));
}else if($type==3){
$row=join('', array_merge(range('a','z'),range('A', 'Z'),range(0, 9)));
};
$row=str_shuffle($row);
$row=substr($row,0,$length);
return $row;
}
/**
* 生成缩略图
* @param int $type //包含数字或者英文
* @param int $length 多少个字符
* @param int $pixel 干扰小点的密度
* @param int $dst_h 干扰线的密度
* @param string //验证码在$_SESSION中的名字
*/
function verifyImage($type=1,$length=4,$pixel=0,$line=0,$sess_name = "verify"){
//session_start();
//创建画布
$width = 100;
$height = 40;
$image = imagecreatetruecolor ( $width, $height );
$white = imagecolorallocate ( $image, 255, 255, 255 );
$black = imagecolorallocate ( $image, 0, 0, 0 );
//用填充矩形填充画布
imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );
$chars = buildRandomString ( $type, $length );
$_SESSION [$sess_name] = $chars;
//$fontfiles = array ("MSYH.TTF", "MSYHBD.TTF", "SIMLI.TTF", "SIMSUN.TTC", "SIMYOU.TTF", "STZHONGS.TTF" );
$fontfiles = array ("SIMKAI.TTF" );
//由于字体文件比较大,就只保留一个字体,如果有需要的同学可以自己添加字体,字体在你的电脑中的fonts文件夹里有,直接运行输入fonts就能看到相应字体
for($i = 0; $i < $length; $i ++) {
$size = mt_rand ( 14, 18 );
$angle = mt_rand ( - 15, 15 );
$x = 5 + $i * $size;
$y = mt_rand ( 20, 26 );
$fontfile = "../fonts/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];
$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );
$text = substr ( $chars, $i, 1 );
imagettftext ( $image, $size, $angle, $x, $y, $color, $fontfile, $text );
}
if ($pixel) {
for($i = 0; $i < 50; $i ++) {
imagesetpixel ( $image, mt_rand ( 0, $width - 1 ), mt_rand ( 0, $height - 1 ), $black );
}
}
if ($line) {
for($i = 1; $i < $line; $i ++) {
$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );
imageline ( $image, mt_rand ( 0, $width - 1 ), mt_rand ( 0, $height - 1 ), mt_rand ( 0, $width - 1 ), mt_rand ( 0, $height - 1 ), $color );
}
}
header ( "content-type:image/gif" );
imagegif ( $image );
imagedestroy ( $image );
}
主要要点:1、如果前面没有申明session_start();则需要申明;2、字体可以在cmf输入fonts下载到自己定义的fonts文件夹;3、$_SESSION [$sess_name]可以通过$_POST获得用户输入的验证码进行比较。
php完整验证码代码的更多相关文章
- 兄弟,你爬虫基础这么好,需要研究js逆向了,一起吧(有完整JS代码)
这几天的确有空了,看更新多快,专门研究了一下几个网站登录中密码加密方法,比起滑块验证码来说都相对简单,适合新手js逆向入门,大家可以自己试一下,试不出来了再参考我的js代码.篇幅有限,完整的js代码在 ...
- 谷歌开源项目Google Preview Image Extractor(PIEX) (附上完整demo代码)
前天偶然看到谷歌开源项目中有一个近乎无人问津的项目Google Preview Image Extractor(PIEX) . 项目地址: https://github.com/google/piex ...
- openssl对数组加密解密的完整实现代码
本例是用C实现的对一个数组进行加密,加密到第二个数组,然后解密到另一个数组的完整实现代码. #include <stdio.h> #include <string.h> #in ...
- 快速双边滤波 附完整C代码
很早之前写过<双边滤波算法的简易实现bilateralFilter>. 当时学习参考的代码来自cuda的样例. 相关代码可以参阅: https://github.com/johng12/c ...
- 基于RNN的音频降噪算法 (附完整C代码)
前几天无意间看到一个项目rnnoise. 项目地址: https://github.com/xiph/rnnoise 基于RNN的音频降噪算法. 采用的是 GRU/LSTM 模型. 阅读下训练代码,可 ...
- 音频压缩编码 opus 附完整C++代码示例
绝大数人都知道mp3格式编码,以及aac,amr等压缩格式编码. 而在语音通信界有一个强悍的音频格式编码opus. 经过实测,压缩比最高可以达到1:10. 100KB 压缩后 10KB 虽然是有损压缩 ...
- 音频降噪算法 附完整C代码
降噪是音频图像算法中的必不可少的. 目的肯定是让图片或语音 更加自然平滑,简而言之,美化. 图像算法和音频算法 都有其共通点. 图像是偏向 空间 处理,例如图片中的某个区域. 图像很多时候是以二维数据 ...
- mser 最大稳定极值区域(文字区域定位)算法 附完整C代码
mser 的全称:Maximally Stable Extremal Regions 第一次听说这个算法时,是来自当时部门的一个同事, 提及到他的项目用它来做文字区域的定位,对这个算法做了一些优化. ...
- 音频自动增益 与 静音检测 算法 附完整C代码
前面分享过一个算法<音频增益响度分析 ReplayGain 附完整C代码示例> 主要用于评估一定长度音频的音量强度, 而分析之后,很多类似的需求,肯定是做音频增益,提高音量诸如此类做法. ...
随机推荐
- Caffe 在 Ubuntu 中安装
Ubuntu Installation General dependencies sudo apt-get install libprotobuf-dev libleveldb-dev libsnap ...
- pathmunge /etc/profile
pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "a ...
- 使用wampserver安装Composer的注意事项
http://getcomposer.org/Composer-Setup.exe 修改C:\wamp\bin\php\php5.3.10中php.ini中的配置 在php.ini中开启php_ope ...
- Linux防火墙iptables学习笔记(三)iptables命令详解和举例[转载]
Linux防火墙iptables学习笔记(三)iptables命令详解和举例 2008-10-16 23:45:46 转载 网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能 ...
- text code
https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/erfilter.cpp
- JavaScript中childNodes、children、nodeValue、nodeType、parentNode、nextSibling详细讲解
其中属性.元素(标签).文本都属于节点 <title></title> <scripttype="text/javascript"> windo ...
- [Redux] Using mapDispatchToProps() Shorthand Notation
We will learn how to avoid the boilerplate code in mapDispatchToProps() for the common case where ac ...
- Java 加密 base64 encode
版权声明:本文为博主原创文章,未经博主允许不得转载. [前言] 计算机中的数据都是二进制的,不管是字符串还是文件,而加密后的也是二进制的, 而我们要看到的往往是字符串,本文就介绍了将byte[]转为各 ...
- python 用pdb调试
简单调试 Python 程序 在 Python 中也可以像 gcc/gdb 那样调试程序,只要在运行 Python 程序时引入 pdb 模块(假设要调试的程序名为 d.py): $ vi d.py ...
- MapReduce中的map个数
在map阶段读取数据前,FileInputFormat会将输入文件分割成split.split的个数决定了map的个数.影响map个数(split个数)的主要因素有: 1) 文件的大小.当块(dfs. ...