漂亮的PHP验证码
<?php
class Imagecode{
private $width ;
private $height;
private $counts;
private $distrubcode;
private $fonturl;
private $session;
function __construct($width = 120,$height = 30,$counts = 5,$distrubcode="1235467890qwertyuipkjhgfdaszxcvbnm",$fonturl="C:\Windows\Fonts\TektonPro-BoldCond.otf"){
$this->width=$width;
$this->height=$height;
$this->counts=$counts;
$this->distrubcode=$distrubcode;
$this->fonturl=$fonturl;
$this->session=$this->sessioncode();
session_start();
$_SESSION['code']=$this->session;
} function imageout(){
$im=$this->createimagesource();
$this->setbackgroundcolor($im);
$this->set_code($im);
$this->setdistrubecode($im);
ImageGIF($im);
ImageDestroy($im);
} private function createimagesource(){
return imagecreate($this->width,$this->height);
}
private function setbackgroundcolor($im){
$bgcolor = ImageColorAllocate($im, rand(200,255),rand(200,255),rand(200,255));//±³¾°ÑÕÉ«
imagefill($im,0,0,$bgcolor);
}
private function setdistrubecode($im){
$count_h=$this->height;
$cou=floor($count_h*2);
for($i=0;$i<$cou;$i++){
$x=rand(0,$this->width);
$y=rand(0,$this->height);
$jiaodu=rand(0,360);
$fontsize=rand(8,15);
$fonturl=$this->fonturl;
$originalcode = $this->distrubcode;
$countdistrub = strlen($originalcode);
$dscode = $originalcode[rand(0,$countdistrub-1)];
$color = ImageColorAllocate($im, rand(40,140),rand(40,140),rand(40,140));
imagettftext($im,$fontsize,$jiaodu,$x,$y,$color,$fonturl,$dscode); }
}
private function set_code($im){
$width=$this->width;
$counts=$this->counts;
$height=$this->height;
$scode=$this->session;
$y=floor($height/2)+floor($height/4);
$fontsize=rand(30,35);
$fonturl="C:\Windows\Fonts\AdobeGothicStd-Bold.otf";//$this->fonturl; $counts=$this->counts;
for($i=0;$i<$counts;$i++){
$char=$scode[$i];
$x=floor($width/$counts)*$i+8;
$jiaodu=rand(-20,30);
$color = ImageColorAllocate($im,rand(0,50),rand(50,100),rand(100,140));
imagettftext($im,$fontsize,$jiaodu,$x,$y,$color,$fonturl,$char);
} }
private function sessioncode(){
$originalcode = $this->distrubcode;
$countdistrub = strlen($originalcode);
$_dscode = "";
$counts=$this->counts;
for($j=0;$j<$counts;$j++){
$dscode = $originalcode[rand(0,$countdistrub-1)];
$_dscode.=$dscode;
}
return $_dscode; }
}
Header("Content-type: image/GIF");
$imagecode=new Imagecode(160,50);
$imagecode->imageout();
漂亮的PHP验证码的更多相关文章
- 很漂亮的PHP验证码(记录)
在提交表单的时候为了防止机器操作或者是恶意的攻击,在填写表单的时候一般都用验证码来过滤掉一些非法提交数据.今天给大家介绍一款超实用超漂亮的PHP验证码库:Captcha. 安装 使用composer: ...
- 一个漂亮的php验证码类
一个漂亮的php验证码类(分享) 作者: 字体:[增加 减小] 类型:转载 下面小编就为大家分享一个漂亮的php验证码类.需要的朋友可以过来参考下 直接上代码: 复制代码 代码如下: //验证 ...
- PHP入门培训教程 一个漂亮的PHP验证码
如何写一个漂亮的PHP验证码?兄弟连PHP培训 小编分享一段代码给大家: <?php class Imagecode{ private $width ; private $height; pri ...
- 一个漂亮的php验证码类(分享)
直接上代码: 复制代码 代码如下: //验证码类class ValidateCode { private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRS ...
- 建立一个漂亮的PHP验证码类文件及调用方式
//验证码类class ValidateCode { private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';/ ...
- 简单漂亮的php验证码函数
/* *说明:函数功能是生成验证码 * 参数说明:输入 长度,宽度,高度 */ function vcode($_code_length = , $_width = , $_height = ){ $ ...
- ASP.NET 漂亮美观的验证码
效果预览: 1.随机码和图片流生成 public class ValidateCode { /// <summary> /// 產生圖形驗證碼. /// </summary> ...
- 一个漂亮的PHP验证码
自己导入字体,可以按照自己的额需要随便修改. <?php class Imagecode{ private $width ; private $height; private $counts; ...
- 献上一款漂亮的手写PHP验证码
献上一款漂亮的PHP验证码,可以根据个人需求作调整,代码如下(审美观不同,欢迎吐槽): <?php /** * Author: xiongwei * Email: 695704253@qq.co ...
随机推荐
- Android AudioPolicyService服务启动过程
AudioPolicyService是策略的制定者,比如什么时候打开音频接口设备.某种Stream类型的音频对应什么设备等等.而AudioFlinger则是策略的执行者,例如具体如何与音频设备通信,如 ...
- OGG FAQ
Q1:oracle_关于参数.ENABLE_GOLDENGATE_REPLICATION A: So, in order to use OGG, on Oracle 11.2.0.4, or Or ...
- 归心似箭,IT达人分享抢票攻略
[51CTO专稿]随着春节一天天临近,“购票难”的问题也愈发凸显,猎豹.火狐.360等“春运抢票神器”占领了各大网站的重要版面,“技术抢票”成为炙手可热的话题,看看身为程序员的邓以克是如何抢到回家的票 ...
- Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
今天在做自定义ViewGroup中,出现了一下错误提示Use View.isInEditMode() in your custom views to skip code when shown in E ...
- Chapter 1 First Sight——2
"Bella," my mom said to me — the last of a thousand times — before I got on the plane. &qu ...
- PHP 代码跟踪
怎么知道代码的执行过程呢,也就是说怎么知道:是先执行哪些代码,然后执行哪些代码呢? 这里有一个非常犀利的函数,可以让你知道代码的执行过程 debug_backtrace() 函数. 来一段代码: L ...
- POJ 2653 Pick-up sticks
计算几何,判断线段相交 注意题目中的一句话:You may assume that there are no more than 1000 top sticks. 我认为是没有描述清楚的,如果不是每次 ...
- nginx keepalived 主从切换
注: LVS + Keepalived 不知道为什么出现一个很郁闷的问题....... ------------------------------------------------------ ...
- UVA 10689 Yet another Number Sequence
简单矩阵快速幂. if(m==1) MOD=10; if(m==2) MOD=100; if(m==3) MOD=1000; if(m==4) MOD=10000; 剩下的就是矩阵快速幂求斐波那契数列 ...
- Section 1.1
Your Ride Is Here /* PROG:ride LANG:C++ */ #include <iostream> #include <cstdio> #includ ...