PHP的中问验证码


Posted in PHP onNovember 25, 2006
<?php 
Class code 
{ 
 var $width =160; //图片的宽 
 var $hight =40; //图片的高 
 var $image; 
 var $red =223; //图片的RGB颜色 
 var $green =225; //红 
 var $blue =227 ;//绿 
 var $pix =227 ;//蓝 
 var $pixcolor; //杂色颜色; 
 var $pixred = 242; //红 
 var $pixgreen = 168;//绿 
 var $pixblue = 162; //蓝 
 var $txt=null;//验证码文字 
 var $txtcode=null; 
 var $txtsub=null; 
 var $pixnum = 300; //杂点数量 
 var $i=0; 
 var $widthpx=0; 
 var $highty=0; 
 var $txtreg=50; 
 var $txtgreen=30; 
 function createimage()  //创建一张图并填色 
 { 
  $this->image = imagecreate($this->width,$this->hight); 
  $this->color = imagecolorallocate($this->image,$this->red,$this->green,$this->blue); 
  return imagefill($this->image,0,0,$this->color); 
 } 
 function createpix() //干扰因素 
 { 
  for($this->i=1;$this->i<$this->pixnum;$this->i++) 
  { 
    $this->widthpx = rand(0,$this->width); 
    $this->highty = rand(0,$this->hight); 
   $this->pixcolor = imagecolorallocate($this->image,$this->pixred,$this->pixgreen,$this->pixblue); 
     imagesetpixel($this->image,$this->widthpx,$this->highty,$this->pixcolor); 
  } 
 } 
  function gettxt() //创建验证码文字 
 { 
  $this->txt = array("我","爱","你","叶","就","慧","明","发","真","的","很","想","不","知","到","为","什","么","就","是","忘","不","了","你","也","许","上","辈","欠","钱"); 
  for($this->i=0;$this->i<6;$this->i++) 
  { 
   $this->sub = $this->txt[rand(0,29)]; 
   $this->txtcode.= $this->sub; 
  } 
  $this->txtcode = iconv("GB2312","UTF-8",$this->txtcode); 
  $_SESSION["code"] = $this->txtcode; //产生的验证ID 
 } 
 function createstring() //创建验证码图片 
 { 
  imagettftext($this->image,20,5,0,40,$this->pixcolor,"C:\WINDOWS\Fonts\simsun.ttc ",$this->txtcode); 
  header("content-type:image/png"); 
  return imagepng($this->image); 
     imagedestroy($this->image); 
 } 
 function getcodeimage()//获得验证码图片 
 { 
  $this->createimage(); 
  $this->gettxt(); 
  $this->createpix();   
  $this->createstring(); 
 } 
} 
?> 
<?php  
session_start();    
$text = new code; 
$text->createimage(); 
$text->gettxt(); 
$text->createpix(); 
$text->createstring(); 
?>
PHP 相关文章推荐
生成静态页面的PHP类
Jul 15 PHP
ADODB的数据库封包程序库
Dec 31 PHP
php 的加密函数 md5,crypt,base64_encode 等使用介绍
Apr 09 PHP
PhpMyAdmin出现export.php Missing parameter: what /export_type错误解决方法
Aug 09 PHP
php数组一对一替换实现代码
Aug 31 PHP
关于Zend Studio 配色方案插件的介绍
Jun 24 PHP
php使用ob_start()实现图片存入变量的方法
Nov 14 PHP
ThinkPHP实现支付宝接口功能实例
Dec 02 PHP
PHP合并discuz用户脚本的方法
Aug 04 PHP
微信支付开发维权通知实例
Jul 12 PHP
php app支付宝回调(异步通知)详解
Jul 25 PHP
一文掌握PHP Xdebug 本地与远程调试(小结)
Apr 23 PHP
mysql建立外键
Nov 25 #PHP
ADODB结合SMARTY使用~超级强
Nov 25 #PHP
ADODB类使用
Nov 25 #PHP
smarty静态实验表明,网络上是错的~呵呵
Nov 25 #PHP
PHP动态变静态原理
Nov 25 #PHP
smarty 原来也不过如此~~呵呵
Nov 25 #PHP
用PHP的ob_start();控制您的浏览器cache!
Nov 25 #PHP
You might like
PHP包含文件函数include、include_once、require、require_once区别总结
2014/04/05 PHP
CI框架在CLI下执行占用内存过大问题的解决方法
2014/06/17 PHP
php更新mysql后获取改变行数的方法
2014/12/25 PHP
PHP实现递归无限级分类
2015/10/22 PHP
删除PHP数组中头部、尾部、任意元素的实现代码
2017/04/10 PHP
基于jquery的图片懒加载js
2010/06/30 Javascript
jQuery 菜单随滚条改为以定位方式(固定要浏览器顶部)
2012/05/24 Javascript
jQuery不兼容input的change事件问题解决过程
2014/12/05 Javascript
AngularJS初始化过程分析(引导程序)
2014/12/06 Javascript
javascript中传统事件与现代事件
2015/06/23 Javascript
bootstrapValidator表单验证插件学习
2016/12/30 Javascript
JS中使用正则表达式g模式和非g模式的区别
2017/04/01 Javascript
Angular2搜索和重置按钮过场动画
2017/05/24 Javascript
js实现微信/QQ直接跳转到支付宝APP打开口令领红包功能
2018/01/09 Javascript
vue百度地图 + 定位的详解
2019/05/13 Javascript
解决echarts 一条柱状图显示两个值,类似进度条的问题
2020/07/20 Javascript
vue中路由跳转不计入history的操作
2020/09/21 Javascript
python 文件与目录操作
2008/12/24 Python
PyQt5每天必学之事件与信号
2018/04/20 Python
解决python大批量读写.doc文件的问题
2018/05/08 Python
django页面跳转问题及注意事项
2019/07/18 Python
python matplotlib 画dataframe的时间序列图实例
2019/11/20 Python
pytorch进行上采样的种类实例
2020/02/18 Python
在python tkinter界面中添加按钮的实例
2020/03/04 Python
Python爬虫requests库多种用法实例
2020/05/28 Python
加拿大折扣、优惠券和交易网站:WagJag
2018/02/07 全球购物
俞敏洪北大演讲稿
2014/05/22 职场文书
党员教师个人对照检查材料(群众路线)
2014/09/26 职场文书
灵山大佛导游词
2015/02/04 职场文书
淘宝客服专员岗位职责
2015/04/07 职场文书
大学生青年志愿者活动总结
2015/05/06 职场文书
2015年财政局工作总结
2015/05/21 职场文书
不同意离婚上诉状
2015/05/23 职场文书
小学五年级班主任工作经验交流材料
2015/11/02 职场文书
使用pandas或numpy处理数据中的空值(np.isnan()/pd.isnull())
2021/05/14 Python
Spring Security使用单点登录的权限功能
2022/04/03 Java/Android