php ci框架验证码实例分析

前端之家收集整理的这篇文章主要介绍了php ci框架验证码实例分析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

PHP代码:@H_502_0@<div class="codetitle"><a style="CURSOR: pointer" data="78374" class="copybut" id="copybut78374" onclick="doCopy('code78374')"> 代码如下:

<div class="codebody" id="code78374">@H_502_0@<?PHP @H_502_0@class Captchacode@H5020@{@H5020@var $width='60';@H5020@var $num='4';@H5020@var $height='20';@H5020@var $name='randcode';@H502_0@public function _construct($conf="")@H5020@{@H5020@if($conf!="")@H5020@{@H5020@foreach($conf as $key=>$value)@H5020@{@H5020@$this->$key=$value;@H5020@}@H5020@}@H5020@}function show()@H5020@{@H5020@Header("Content-type: image/gif");@H5020@/*@H5020@* 初始化@H5020@*/@H5020@$border = 0; //是否要边框 1要:0不要@H5020@$how = $this->num; //验证码位数@H502_0@$w = $this->width; //图片宽度@H_502_0@$h = $this->height; //图片高度@H_5020@$fontsize = 5; //字体大小@H502_0@$alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母@H_502_0@$number = "023456789"; //验证码内容2:数字@H_5020@$randcode = ""; //验证码字符串初始化@H502_0@srand((double)microtime()1000000); //初始化随机数种子$im = ImageCreate($w,$h); //创建验证图片/@H_5020@* 绘制基本框架@H5020@*/@H5020@$bgcolor = ImageColorAllocate($im,255,255); //设置背景颜色@H5020@ImageFill($im,$bgcolor); //填充背景色@H5020@if($border)@H5020@{@H5020@$black = ImageColorAllocate($im,0); //设置边框颜色@H5020@ImageRectangle($im,$w-1,$h-1,$black);//绘制边框@H5020@}/*@H502_0@ 逐位产生随机字符@H_502_0@/@H_5020@for($i=0; $i<$how; $i++)@H5020@{ @H502_0@$alpha_or_number = mtrand(0,1); //字母还是数字@H502_0@$str = $alpha_ornumber ? $alpha : $number;@H502_0@$which = mtrand(0,strlen($str)-1); //取哪个字符@H5020@$code = substr($str,$which,1); //取字符@H5020@$j = !$i ? 4 : $j+15; //绘字符位置@H502_0@$color3 = ImageColorAllocate($im,mtrand(0,100),100)); //字符随即颜色@H5020@ImageChar($im,$fontsize,$j,3,$code,$color3); //绘字符@H5020@$randcode .= $code; //逐位加入验证码字符串@H5020@}/*@H502_0@ 添加干扰@H_502_0@/@H_5020@for($i=0; $i<5; $i++)//绘背景干扰线@H5020@{ @H5020@$color1 = ImageColorAllocate($im,255),255)); //干扰线颜色@H502_0@ImageArc($im,mt_rand(-5,$w),$h),mtrand(20,300),200),55,44,$color1); //干扰线@H5020@} @H5020@for($i=0; $i<$how*15; $i++)//绘背景干扰点@H5020@{ @H5020@$color2 = ImageColorAllocate($im,255)); //干扰点颜色 @H5020@ImageSetPixel($im,$color2); //干扰点@H502_0@}//把验证码字符串写入session//$this->session->set_userdata(array($this->name=>$randcode));$SESSION[$this->name]=$randcode;@H5020@/绘图结束/@H5020@Imagegif($im);@H5020@ImageDestroy($im);@H5020@/绘图结束/@H5020@}@H5020@}@H5020@?>@H5020@
@H502_0@调用PHP代码:@H_502_0@<div class="codetitle"><a style="CURSOR: pointer" data="70088" class="copybut" id="copybut70088" onclick="doCopy('code70088')"> 代码如下:
<div class="codebody" id="code70088">@H_502_0@ function verifyimage() {@H502_0@ $conf['name'] = 'verifycode'; //作为配置参数@H502_0@ $this->load->library('libcaptcha',$conf);@H502_0@ $this->libcaptcha->show();@H502_0@ $yzm_session = $this->session->userdata('verifycode');@H502_0@ echo $yzmsession;@H5020@ }@H5020@
@H502_0@HTML代码:@H_502_0@<div class="codetitle"><a style="CURSOR: pointer" data="48062" class="copybut" id="copybut48062" onclick="doCopy('code48062')"> 代码如下:
<div class="codebody" id="code48062">@H_5020@
@H5020@
验证码:
@H
5020@
@H502_0@ <input type="text" name="verify_text" id="verifytext" class="yzma" value="">@H502_0@ 验证码@H_502_0@ <a href="javascript:changeCode();" class="change_yz">换一张

<dd class="tips_wrong">验证码不正确
<dd class="tips_correct">


js代码:
<div class="codetitle"><a style="CURSOR: pointer" data="87583" class="copybut" id="copybut87583" onclick="doCopy('code87583')"> 代码如下:
<div class="codebody" id="code87583">@H_5020@<script type="text/javascript">@H5020@ function changeCode(){@H502_0@ FS.query("#verify_code").src ="/user/verifyimage?r=" + Math.random();@H5020@ }@H5020@@H5020@@H502_0@

ci框架php验证码验证码验证码

猜你在找的PHP相关文章