用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 相关文章推荐
ftp类(example.php)
Oct 09 PHP
默默简单的写了一个模板引擎
Jan 02 PHP
用php实现让页面只能被百度gogole蜘蛛访问的方法
Dec 29 PHP
php 多关键字 高亮显示实现代码
Apr 23 PHP
PHP fastcgi模式上传大文件(大约有300多K)报错
Sep 28 PHP
常用的php图片处理类(水印、等比缩放、固定高宽)分享
Jun 19 PHP
学习PHP Cookie处理函数
Aug 09 PHP
PHP仿微信发红包领红包效果
Oct 30 PHP
PHP微信分享开发详解
Jan 14 PHP
PHP实现生成模糊图片的方法示例
Dec 21 PHP
php PDO属性设置与操作方法分析
Dec 27 PHP
thinkphp5.1 框架钩子和行为用法实例分析
May 25 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代码包装修正版
2008/03/15 PHP
php 备份数据库代码(生成word,excel,json,xml,sql)
2013/06/23 PHP
php仿QQ验证码的实例分析
2013/07/01 PHP
Symfony2框架创建项目与模板设置实例详解
2016/03/17 PHP
PHP使用http_build_query()构造URL字符串的方法
2016/04/02 PHP
php基于mcrypt_encrypt和mcrypt_decrypt实现字符串加密解密的方法
2016/07/12 PHP
Laravel 手动开关 Eloquent 修改器的操作方法
2019/12/30 PHP
PHP 范围解析操作符(::)用法分析【访问静态成员和类常量】
2020/04/14 PHP
Save a File Using a File Save Dialog Box
2007/06/18 Javascript
基于jquery实现图片广告轮换效果代码
2011/07/07 Javascript
jQuery登陆判断简单实现代码
2013/04/21 Javascript
JS控件ASP.NET的treeview控件全选或者取消(示例代码)
2013/12/16 Javascript
JS中获取函数调用链所有参数的方法
2015/05/07 Javascript
jQuery表单验证简单示例
2016/10/17 Javascript
Angular2从搭建环境到开发步骤详解
2016/10/17 Javascript
jQuery联动日历的实例解析
2016/12/02 Javascript
vue params、query传参使用详解
2017/09/12 Javascript
详解vue+css3做交互特效的方法
2017/11/20 Javascript
微信小程序动态显示项目倒计时
2019/06/20 Javascript
让你30分钟快速掌握vue3教程
2020/10/26 Javascript
Python time模块详解(常用函数实例讲解,非常好)
2014/04/24 Python
python中学习K-Means和图片压缩
2017/11/20 Python
Python使用post及get方式提交数据的实例
2019/01/24 Python
python批量修改图片尺寸,并保存指定路径的实现方法
2019/07/04 Python
使用django和vue进行数据交互的方法步骤
2019/11/11 Python
kafka-python 获取topic lag值方式
2019/12/23 Python
基于keras中的回调函数用法说明
2020/06/17 Python
基于python requests selenium爬取excel vba过程解析
2020/08/12 Python
python实现三种随机请求头方式
2021/01/05 Python
生物科学专业职业规划书范文
2014/02/11 职场文书
小学一年级评语大全
2014/04/22 职场文书
中华魂演讲稿
2014/05/13 职场文书
销售员试用期自我评价
2014/09/15 职场文书
玩手机检讨书1000字
2014/10/20 职场文书
2015年乡镇纪委工作总结
2015/05/26 职场文书
趣味运动会口号
2015/12/24 职场文书