用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 相关文章推荐
《APMServ 5.1.2》使用图解
Oct 23 PHP
PHP4中session登录页面的应用
Jul 25 PHP
PHP 开源AJAX框架14种
Aug 24 PHP
浅析php面向对象public private protected 访问修饰符
Jun 30 PHP
php 购物车完整实现代码
Jun 05 PHP
最常用的8款PHP调试工具
Jul 06 PHP
php Imagick获取图片RGB颜色值
Jul 28 PHP
Javascript与PHP验证用户输入URL地址是否正确
Oct 09 PHP
php程序总是提示验证码输入有误解决方案
Jan 07 PHP
PHP实现登录注册之BootStrap表单功能
Sep 03 PHP
PHP递归实现快速排序的方法示例
Dec 18 PHP
php设计模式之适配器模式实例分析【星际争霸游戏案例】
Apr 07 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判断服务器是否支持Gzip压缩功能
2013/09/24 PHP
PHP中多维数组的foreach遍历示例
2014/06/13 PHP
使用GDB调试PHP代码,解决PHP代码死循环问题
2015/03/02 PHP
php文档工具PHP Documentor安装与使用方法
2016/01/25 PHP
Laravel与CI框架中截取字符串函数
2016/05/08 PHP
Zend Framework入门教程之Zend_Db数据库操作详解
2016/12/08 PHP
syntaxhighlighter 使用方法
2007/07/02 Javascript
深入理解Javascript闭包 新手版
2010/12/28 Javascript
js原生态函数中使用jQuery中的 $(this)无效的解决方法
2011/05/25 Javascript
js如何获取file控件的完整路径具体实现代码
2013/05/15 Javascript
JQuery中extend使用介绍
2014/03/13 Javascript
浅析创建javascript对象的方法
2016/05/13 Javascript
AngularJS入门教程之过滤器用法示例
2016/11/02 Javascript
JavaScript用200行代码制作打飞机小游戏实例
2017/06/21 Javascript
JavaScript事件方法(实例讲解)
2017/06/27 Javascript
Iview Table组件中各种组件扩展的使用
2018/10/20 Javascript
详解Webpack4多页应用打包方案
2020/07/16 Javascript
Python导入oracle数据的方法
2015/07/10 Python
python 调用win32pai 操作cmd的方法
2017/05/28 Python
python学习笔记--将python源文件打包成exe文件(pyinstaller)
2018/05/26 Python
python3使用matplotlib绘制散点图
2019/03/19 Python
在SQLite-Python中实现返回、查询中文字段的方法
2019/07/17 Python
如何基于python操作json文件获取内容
2019/12/24 Python
python关于变量名的基础知识点
2020/03/03 Python
python实现飞机大战项目
2020/03/11 Python
HTML5 localStorage使用总结
2017/02/22 HTML / CSS
化学系大学生自荐信范文
2014/03/01 职场文书
股份转让协议书
2014/04/12 职场文书
党员群众路线对照检查材料
2014/08/31 职场文书
2014年节能工作总结
2014/12/18 职场文书
小学母亲节活动总结
2015/02/10 职场文书
2015年教师自我评价范文
2015/03/04 职场文书
运动会3000米加油稿
2015/07/21 职场文书
2019最新婚庆对联集锦!
2019/07/10 职场文书
遇事可以测出您的见识与格局
2019/09/16 职场文书
Java 中的 Lambda List 转 Map 的多种方法详解
2022/07/07 Java/Android