用PHP实现登陆验证码(类似条行码状)


Posted in PHP onOctober 09, 2006

<?php

function UPCAbarcode($code) {
  $lw = 2; $hi = 100;
  $Lencode = array('0001101','0011001','0010011','0111101','0100011',
                   '0110001','0101111','0111011','0110111','0001011');
  $Rencode = array('1110010','1100110','1101100','1000010','1011100',
                   '1001110','1010000','1000100','1001000','1110100');
  $ends = '101'; $center = '01010';
  /* UPC-A Must be 11 digits, we compute the checksum. */
  if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); }
  /* Compute the EAN-13 Checksum digit */
  $ncode = '0'.$code;
  $even = 0; $odd = 0;
  for ($x=0;$x<12;$x++) {
    if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }
  }
  $code.=(10 - (($odd * 3 + $even) % 10)) % 10;
  /* Create the bar encoding using a binary string */
  $bars=$ends;
  $bars.=$Lencode[$code[0]];
  for($x=1;$x<6;$x++) {
    $bars.=$Lencode[$code[$x]];
  }
  $bars.=$center;
  for($x=6;$x<12;$x++) {
    $bars.=$Rencode[$code[$x]];
  }
  $bars.=$ends;
  /* Generate the Barcode Image */
  $img = ImageCreate($lw*95+30,$hi+30);
  $fg = ImageColorAllocate($img, 0, 0, 0);
  $bg = ImageColorAllocate($img, 255, 255, 255);
  ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg);
  $shift=10;
  for ($x=0;$x<strlen($bars);$x++) {
    if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; }
    if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }
    ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
  }
  /* Add the Human Readable Label */
  ImageString($img,4,5,$hi-5,$code[0],$fg);
  for ($x=0;$x<5;$x++) {
    ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
    ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
  }
  ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg);
  /* Output the Header and Content. */
  header("Content-Type: image/png");
  ImagePNG($img);
}

UPCAbarcode('12345678901');

?>

用PHP实现登陆验证码(类似条行码状)

PHP 相关文章推荐
php+dbfile开发小型留言本
Oct 09 PHP
Discuz!5的PHP代码高亮显示插件(黑暗中的舞者更新)
Jan 29 PHP
sourcesafe管理phpproj文件的补充说明(downmoon)
Apr 11 PHP
解析关于java,php以及html的所有文件编码与乱码的处理方法汇总
Jun 24 PHP
ThinkPHP中order()使用方法详解
Apr 19 PHP
Netbeans 8.2将支持PHP7 更精彩
Jun 13 PHP
php使用curl代理实现抓取数据的方法
Feb 03 PHP
PHP常用算法和数据结构示例(必看篇)
Mar 15 PHP
yii2中LinkPager增加总页数和总记录数的实例
Aug 28 PHP
php记录搜索引擎爬行记录的实现代码
Mar 02 PHP
PHP封装的完整分页类示例
Aug 21 PHP
有关PHP 中 config.m4 的探索
Aug 26 PHP
用PHP创建PDF中文文档
Oct 09 #PHP
PHP与javascript对多项选择的处理
Oct 09 #PHP
3
Oct 09 #PHP
example2.php
Oct 09 #PHP
对盗链说再见...
Oct 09 #PHP
PHP出错界面
Oct 09 #PHP
ftp类(myftp.php)
Oct 09 #PHP
You might like
php HTML无刷新提交表单
2016/04/05 PHP
通过js脚本复制网页上的一个表格的不错实现方法
2006/12/29 Javascript
用innerhtml提高页面打开速度的方法
2013/08/02 Javascript
页面定时刷新(1秒刷新一次)
2013/11/22 Javascript
js中split函数的使用方法说明
2013/12/26 Javascript
浅析IE10兼容性问题(frameset的cols属性)
2014/01/03 Javascript
JS,Jquery获取select,dropdownlist,checkbox下拉列表框的值(示例代码)
2014/01/11 Javascript
Javascript基础教程之argument 详解
2015/01/18 Javascript
充分发挥Node.js程序性能的一些方法介绍
2015/06/23 Javascript
DropDownList控件绑定数据源的三种方法
2016/12/24 Javascript
详解Vue中使用v-for语句抛出错误的解决方案
2017/05/04 Javascript
详解性能更优越的小程序图片懒加载方式
2018/07/18 Javascript
Node在Controller层进行数据校验的过程详解
2020/08/28 Javascript
[01:17:55]VGJ.T vs Mineski 2018国际邀请赛小组赛BO2 第一场 8.18
2018/08/20 DOTA
[01:33]完美世界DOTA2联赛PWL S3 集锦第二期
2020/12/21 DOTA
使用PyCharm配合部署Python的Django框架的配置纪实
2015/11/19 Python
简单讲解Python中的数字类型及基本的数学计算
2016/03/11 Python
详解Python list 与 NumPy.ndarry 切片之间的对比
2017/07/24 Python
python连接数据库的方法
2017/10/19 Python
在django中图片上传的格式校验及大小方法
2019/07/28 Python
wxPython实现文本框基础组件
2019/11/18 Python
python 爬取免费简历模板网站的示例
2020/09/27 Python
详解pycharm自动import所需的库的操作方法
2020/11/30 Python
中国排名第一的外贸销售网站:LightInTheBox.com(兰亭集势)
2016/10/28 全球购物
英国性能汽车零件和发动机配件在线:Maxpeedingrods
2019/11/05 全球购物
中医临床专业自我鉴定范文
2014/01/15 职场文书
运动会广播稿30字
2014/01/21 职场文书
物流创业计划书
2014/02/01 职场文书
创先争优演讲稿
2014/09/15 职场文书
教师先进事迹材料
2014/12/16 职场文书
客房领班岗位职责
2015/02/11 职场文书
海上钢琴师观后感
2015/06/03 职场文书
判断Python中的Nonetype类型
2021/05/25 Python
漫画「你在春天醒来」第10卷封面公开
2022/03/21 日漫
redis sentinel监控高可用集群实现的配置步骤
2022/04/01 Redis
Zabbix6通过ODBC方式监控Oracle 19C的详细过程
2022/09/23 Servers