用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 方便水印和缩略图的图形类
May 21 PHP
php学习笔记 php中面向对象三大特性之一[封装性]的应用
Jun 13 PHP
ThinkPHP3.1新特性之查询条件预处理简介
Jun 19 PHP
Yii调试SQL的常用方法
Jul 09 PHP
浅谈php命令行用法
Feb 04 PHP
php计算年龄精准到年月日
Nov 17 PHP
PHP按指定键值对二维数组进行排序的方法
Dec 22 PHP
WordPress中创建用户角色的相关PHP函数使用详解
Dec 25 PHP
Laravel中Trait的用法实例详解
Mar 16 PHP
Laravel框架中VerifyCsrfToken报错问题的解决
Aug 30 PHP
php微信开发之谷歌测距
Jun 14 PHP
PHP封装cURL工具类与应用示例
Jul 01 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小技巧之函数重载
2014/06/02 PHP
PHP实现多关键字加亮功能
2016/10/21 PHP
从Ajax到JQuery Ajax学习
2007/02/14 Javascript
jquery中的$(document).ready()与window.onload的区别
2009/11/18 Javascript
zeroclipboard复制到剪切板的flash
2010/08/04 Javascript
JavaScript中获取高度和宽度函数总结
2014/10/08 Javascript
jquery实现顶部向右伸缩的导航区域代码
2015/09/02 Javascript
推荐10 个很棒的 jQuery 特效代码
2015/10/04 Javascript
ajax在兼容模式下失效的快速解决方法
2016/03/22 Javascript
Bootstrap警告(Alerts)的实现方法
2017/03/22 Javascript
js获取css的各种样式并且设置他们的方法
2017/08/22 Javascript
vue-cli 默认路由再子路由选中下的选中状态问题及解决代码
2018/09/06 Javascript
解决基于 keep-alive 的后台多级路由缓存问题
2020/12/23 Javascript
[40:55]Liquid vs LGD 2018国际邀请赛小组赛BO2 第二场 8.16
2018/08/17 DOTA
使用python实现递归版汉诺塔示例(汉诺塔递归算法)
2014/04/08 Python
Python中的XML库4Suite Server的介绍
2015/04/14 Python
python实现机械分词之逆向最大匹配算法代码示例
2017/12/13 Python
Flask框架使用DBUtils模块连接数据库操作示例
2018/07/20 Python
matplotlib给子图添加图例的方法
2018/08/03 Python
python读取xlsx的方法
2018/12/25 Python
python opencv 简单阈值算法的实现
2019/08/04 Python
Django url,从一个页面调到另个页面的方法
2019/08/21 Python
matplotlib quiver箭图绘制案例
2020/04/17 Python
html5 figure和figcaption的使用方法
2018/09/10 HTML / CSS
科颜氏印度官网:Kiehl’s印度
2021/02/20 全球购物
什么是接口(Interface)?
2013/02/01 面试题
光学与应用专业毕业生求职信
2014/09/01 职场文书
2014年车间主任工作总结
2014/12/10 职场文书
市场总监岗位职责
2015/02/11 职场文书
优秀英文求职信范文
2015/03/19 职场文书
英文产品推荐信
2015/03/27 职场文书
公司内部升职自荐信
2015/03/27 职场文书
微信小程序实现拍照和相册选取图片
2021/05/09 Javascript
Nginx反向代理至go-fastdfs案例讲解
2021/08/02 Servers
Rust 连接 PostgreSQL 数据库的详细过程
2022/01/22 PostgreSQL
MySQL 原理与优化之原数据锁的应用
2022/08/14 MySQL