/*

* 说明:生成随机码,并用图形方式显示随机码。

*/

$ViewRandomCode = mt_rand(1000,10000);

session_start();

$_SESSION['checksum'] = $ViewRandomCode;

function set_4pixel($r, $g, $b, $x, $y)

{

global $sx, $sy, $pixels;

$ofs = 3 * ($sx * $y + $x);

$pixels[$ofs] = chr($r);

$pixels[$ofs + 1] = chr($g);

$pixels[$ofs + 2] = chr($b);

$pixels[$ofs + 3] = chr($r);

$pixels[$ofs + 4] = chr($g);

$pixels[$ofs + 5] = chr($b);

$ofs += 3 * $sx;

$pixels[$ofs] = chr($r);

$pixels[$ofs + 1] = chr($g);

$pixels[$ofs + 2] = chr($b);

$pixels[$ofs + 3] = chr($r);

$pixels[$ofs + 4] = chr($g);

$pixels[$ofs + 5] = chr($b);

}

//生成数字图象的函数

function draw2digits($x, $y, $number)

{

draw_digit($x, $y, (int) ($number / 10));

draw_digit($x + 11, $y, $number % 10);

}

function draw_digit($x, $y, $digit)

{

global $sx, $sy, $pixels, $digits, $lines;

$digit = $digits[$digit];

$m = 8;

for ($b = 1, $i = 0; $i < 7; $i++, $b *= 2)

{

if (($b & $digit) == $b) {

$j = $i * 4;

$x0 = $lines[$j] * $m + $x;

$y0 = $lines[$j + 1] * $m + $y;

$x1 = $lines[$j + 2] * $m + $x;

$y1 = $lines[$j + 3] * $m + $y;

if ($x0 == $x1) {

$ofs = 3 * ($sx * $y0 + $x0);

for ($h = $y0; $h <= $y1; $h++, $ofs += 3 * $sx) {

$pixels[$ofs] = chr(0);

$pixels[$ofs + 1] = chr(0);

$pixels[$ofs + 2] = chr(0);

}

} else {

$ofs = 3 * ($sx * $y0 + $x0);

for ($w = $x0; $w <= $x1; $w++) {

$pixels[$ofs++] = chr(0);

$pixels[$ofs++] = chr(0);

$pixels[$ofs++] = chr(0);

}

}

}

}

}

//将文字加入到图象中

function add_chunk($type)

{

global $result, $data, $chunk, $crc_table;

// chunk :为层

// length: 4 字节: 用来计算 chunk

// chunk type: 4 字节

// chunk data: length bytes

// CRC: 4 字节: 循环冗余码校验

// copy data and create CRC checksum

$len = strlen($data);

$chunk = pack(“c*”, ($len >> 24) & 255,

($len >> 16) & 255,

($len >> 8) & 255,

$len & 255);

$chunk .= $type;

$chunk .= $data;

// calculate a CRC checksum with the bytes chunk[4..len-1]

$z = 16777215;

$z |= 255 << 24;

$c = $z;

for ($n = 4; $n < strlen($chunk); $n++) {

$c8 = ($c >> 8) & 0xffffff;

$c = $crc_table[($c ^ ord($chunk[$n])) & 0xff] ^ $c8;

}

$crc = $c ^ $z;

$chunk .= chr(($crc >> 24) & 255);

$chunk .= chr(($crc >> 16) & 255);

$chunk .= chr(($crc >> 8) & 255);

$chunk .= chr($crc & 255);

// 将结果加到$result中

$result .= $chunk;

}

//主程序

$sx = 55;

$sy = 21;

$pixels = rand(100,99990)%2?”qwer”:”";

// 填充

for ($h = 0; $h < $sy; $h++)

{

for ($w = 0; $w < $sx; $w++)

{

$r = 100 / $sx * $w + 155;

$g = 100 / $sy * $h + 155;

$b = 255 – (100 / ($sx + $sy) * ($w + $h));

$pixels .= chr($r);

$pixels .= chr($g);

$pixels .= chr($b);

}

}

$checknum = isset($ViewRandomCode)?$ViewRandomCode:1234;

$h = (int)($checknum/100);

$m = (int)($checknum%100);

$digits = array(95, 5, 118, 117, 45, 121, 123, 69, 127, 125);

$lines = array(1, 1, 1, 2, 0, 1, 0, 2, 1, 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 2, 0, 1, 1, 1, 0, 0, 1, 0);

draw2digits(4, 2, $h);

draw2digits(30, 2, $m);

// set_4pixel(0, 0, 0, 26, 7);

// set_4pixel(0, 0, 0, 26, 13);

// 创建循环冗余码校验表

$z = -306674912; // = 0xedb88320

for ($n = 0; $n < 256; $n++) {

$c = $n;

for ($k = 0; $k < 8; $k++) {

$c2 = ($c >> 1) & 0×7fffffff;

if ($c & 1) $c = $z ^ ($c2); else $c = $c2;

}

$crc_table[$n] = $c;

}

// PNG file signature

$result = pack(“c*”, 137,80,78,71,13,10,26,10);

// IHDR chunk data:

// width: 4 bytes

// height: 4 bytes

// bit depth: 1 byte (8 bits per RGB value)

// color type: 1 byte (2 = RGB)

// compression method: 1 byte (0 = deflate/inflate)

// filter method: 1 byte (0 = adaptive filtering)

// interlace method: 1 byte (0 = no interlace)

$data = pack(“c*”, ($sx >> 24) & 255,

($sx >> 16) & 255,

($sx >> 8) & 255,

$sx & 255,

($sy >> 24) & 255,

($sy >> 16) & 255,

($sy >> 8) & 255,

$sy & 255,

8,

2,

0,

0,

0);

add_chunk(“IHDR”);

// 以下不敢乱翻译,请自行参考

// scanline:

// filter byte: 0 = none

// RGB bytes for the line

// the scanline is compressed with “zlib”, method 8 (RFC-1950):

// compression method/flags code: 1 byte ($78 = method 8, 32k window)

// additional flags/check bits: 1 byte ($01: FCHECK = 1, FDICT = 0, FLEVEL = 0)

// compressed data blocks: n bytes

// one block (RFC-1951):

// bit 0: BFINAL: 1 for the last block

// bit 1 and 2: BTYPE: 0 for no compression

// next 2 bytes: LEN (LSB first)

// next 2 bytes: one’s complement of LEN

// LEN bytes uncompressed data

// check value: 4 bytes (Adler-32 checksum of the uncompressed data)

//

$len = ($sx * 3 + 1) * $sy;

$data = pack(“c*”, 0×78, 0×01,

1,

$len & 255,

($len >> 8) & 255,

255 – ($len & 255),

255 – (($len >> 8) & 255));

$start = strlen($data);

$i2 = 0;

for ($h = 0; $h < $sy; $h++) {

$data .= chr(0);

for ($w = 0; $w < $sx * 3; $w++) {

$data .= $pixels[$i2++];

}

}

// calculate a Adler32 checksum with the bytes data[start..len-1]

$s1 = 1;

$s2 = 0;

for ($n = $start; $n < strlen($data); $n++) {

$s1 = ($s1 + ord($data[$n])) % 65521;

$s2 = ($s2 + $s1) % 65521;

}

$adler = ($s2 << 16) | $s1;

$data .= chr(($adler >> 24) & 255);

$data .= chr(($adler >> 16) & 255);

$data .= chr(($adler >> 8) & 255);

$data .= chr($adler & 255);

add_chunk(“IDAT”);

// IEND: marks the end of the PNG-file

$data = “”;

add_chunk(“IEND”);

// 列印图象

echo($result);

?>

php游客随机代码,php生成随机码的一段代码相关推荐

  1. oracle 生成随机姓名_Oracle生成随机码

    本人网站交友乐www.jyoule.com 需要经常生成随机的活动码,用于制作卡片密码或通过网络发送.活动码的生成规则是采用唯一的字符串开头后面是随机数字,比如AZ00001.使用程序生成活动码速度较 ...

  2. php html实例代码,PHP生成HTML静态页面实例代码

    为cd2sc.com网站功能而开发,代码为本人原创,生成速度一般. (出于众所周知的原因,涉及到数据库的数据字段名称做了改动,并且为了代码明晰去掉了参数过滤的部分) 说明:原动态地址为 moban.p ...

  3. 50行python代码自动生成文章_50行Python代码,教你获取公众号全部文章

    > 本文首发自公众号:python3xxx 爬取公众号的方式常见的有两种 - 通过搜狗搜索去获取,缺点是只能获取最新的十条推送文章 - 通过微信公众号的素材管理,获取公众号文章.缺点是需要申请自 ...

  4. php随机数四位,生成四位随机数的PHP代码

    纯数字的四位随机数 rand(1000,9999) 数字和字符混搭的四位随机字符串: function GetRandStr($len) { $chars = array( "a" ...

  5. 通过wsdl2java工具生成客户端段代码(wsdl2java -p cn.com.css.misps.graph.webservice.impl -d F:\src -all http://10.)

    首先当前是从官网下载cxf组件. Java代码 http://cxf.apache.org/download.html http://cxf.apache.org/download.html 下载后解 ...

  6. 英飞凌代码生成_利用MATLAB-RTW的嵌入式代码自动生成与整合

    2018 收稿日期 :2018 - 01 - 02 收修改稿日期 :2018 - 02 - 01 基金项目 : 国家自然科学基金项目 (51405270) 资助 . 作者简介 : 陈 攀 , 男 ,1 ...

  7. hbuilderx代码自动补全_DL时代的代码补全利器,北大出品,效果远超语言模型

    从程序员到数据工程师,编写程序代码是一项基本功,但是编写冗长代码的过程也极大地消耗了开发者的耐心.近来,有不少关于代码补全工具的消息爆出,例如,来自美国的 Kite,来自加拿大的 TabNine 等, ...

  8. 从固定管线到可编程管线:十段代码入门OpenGL

    文章目录 1. 最简单的OpenGL应用程序 2. 视点系统和投影矩阵 3. 深度缓冲区和深度测试 4. 模型的旋转和平移 5. VBO和顶点混合数组 6. 纹理映射和纹理坐标 7. 光照和法向量计算 ...

  9. 奥哲被曝将发布AI低代码平台,AIGC会改变低代码行业格局吗?

    时下火热的AIGC与低代码开发,是否能碰撞出新的火花? 日前,作者从多位独立信源处获悉,企业数字化服务商奥哲旗下的低代码平台"氚云"已融入AI相关产品,或将下半年正式上线发布. 根 ...

最新文章

  1. 【Groovy】Groovy 动态语言特性 ( Groovy 语言与 Java 语言执行效率对比 | 以动态特性编译的 Groovy 类 | 以静态特性编译的 Groovy 类 )
  2. 科大星云诗社动态20220104
  3. 二叉树的应用 表达式处理_【每日编程208期】2018年408应用题41题
  4. 比特币技术公司创始人:ICO是一场被骗子玩弄的网络泡沫
  5. 怎么查看页面跳转过程_faststone注册码怎么获取?英文官网打不开
  6. 139团队(大型研发团队,大型敏捷开发团队,大型团队结构,敏捷绩效管理)...
  7. 网络中计算机传输信息时所遵从的不同规则,2012年上海市高中学业水平考试信息科技试卷(第6套)...
  8. Html+CSS基础之img标签
  9. 网页转PDF 在线工具 输入网址获取PDF
  10. php实现根据身份证获取年龄的函数
  11. 如何去除Excel图表网格线?
  12. 电脑一启动吃鸡就重启计算机,玩吃鸡老是重启电脑
  13. linux系统玩什么游戏,linux系统可以玩什么网游
  14. 超简单微信登录(微信SDK接入、友盟SDK接入)
  15. 计算机wifi无法打开,苹果Mac电脑WiFi无法打开解决办法
  16. python爬虫爬取图片代码_Python爬虫爬取煎蛋网图片代码实例
  17. Reasoning about Entailment with Neural Attention
  18. 微信传文件又慢又限制大小?试试这3个免费在线传文件工具!
  19. CMTime,CMTimeMake CMTimeMakeWithSeconds
  20. 安霸预发布14nm工艺的ISP芯片

热门文章

  1. 这四种攻击单片机的主要技术你了解多少?
  2. 关于半马尔可夫(semi-markov)的一个形象解释
  3. android界面实现框架内页面跳转_KVM虚拟化管理平台的实现
  4. win10下最新MySQL8.0安装与环境配置,Navicat图形化管理工具连接,完整详细可收藏
  5. html悬浮弹窗后面背景变深,JS+CSS实现Div弹出窗口同时背景变暗的方法
  6. php中数组生成下拉选项,php利用数组填充下拉列表框
  7. airpods耳机敲击没反应_iOS11.2.6造成AirPods耳机出现奇怪问题 网友:解决方法很简单...
  8. axios 跨域_当遇到跨域开发时,我们如何处理好前后端配置和请求库封装
  9. 【洛谷】P4643 【模板】动态dp
  10. 有关struts2中用到 js 总结