<?php
# @PAOCMS & PAOPHP
# @Author: Wasing.tao (陶之11)
# @Contact: admin@paophp.com;
# @Package: PAOPHP Captcha;
# @Support: http://bbs.paophp.com/thread-41-1-1.html
# @Copyright: (c) 2014 Paophp.com All rights reserved.
# @Description: The Captcha Style Copyright by Paocms
# @欢迎加入【珠三角PHP联盟群】: 5579345 (汇集高端PHP大牛技术交流)
# @参数说明及使用方法请看:bbs.paophp.com;
class Captcha{
var $image = null;
var $fonts = './Fonts/';
var $width = 100;
var $height = 30;
var $length = 4;
var $phrase = null;
var $string = array('A','B','C','D','E','F','H','J','K','L','M','N','P','R','S','T','U','V','W','X','Y','Z');
public function __construct()
{
if (!extension_loaded("gd")) exit("Captcha Unable Load GD Library Copyright paophp.com");
}
public function Phrase()
{
if (strlen($this->phrase) != $this->length) {
$phrase = null;
$rand = array_rand($this->string, $this->length);
foreach ($rand as $index)
$phrase .= $this->string[$index];
$this->phrase = $phrase;
}
return $this->phrase;
}
public function Generate()
{
$image = is_resource($this->image) ? $this->image : $this->GenerateImage();
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
private function CreateImage()
{
if (!is_resource($this->image)) {
$this->image = imagecreatetruecolor($this->width, $this->height);
$color1 = imagecolorallocate($this->image, mt_rand(200, 255),mt_rand(200, 255), mt_rand(150, 255));
$color2 = imagecolorallocate($this->image, mt_rand(200, 255),mt_rand(200, 255), mt_rand(150, 255));
$color1 = imagecolorsforindex($this->image, $color1);
$color2 = imagecolorsforindex($this->image, $color2);
$steps = $this->width;
$r1 = ($color1['red'] - $color2['red']) / $steps;
$g1 = ($color1['green'] - $color2['green']) / $steps;
$b1 = ($color1['blue'] - $color2['blue']) / $steps;
$x1 = 0; $y1 =& $i; $x2 = $this->width; $y2 =& $i;
for ($i = 0; $i <= $steps; $i++) {
$r2 = $color1['red'] - floor($i * $r1);
$g2 = $color1['green'] - floor($i * $g1);
$b2 = $color1['blue'] - floor($i * $b1);
$color = imagecolorallocate($this->image, $r2, $g2, $b2);
imageline($this->image, $x1, $y1, $x2, $y2, $color);
}
for ($i = 0, $count = mt_rand(10, 20); $i < $count; $i++) {
$color = imagecolorallocatealpha($this->image, mt_rand(20, 255), mt_rand(20, 255),
mt_rand(100, 255), mt_rand(80, 120));
imageline($this->image, mt_rand(0, $this->width), 0,
mt_rand(0, $this->width), $this->height, $color);
}
}
return $this->image;
}
public function GenerateImage($phrase = null)
{
$image = $this->CreateImage();
$phrase == null && $phrase = $this->Phrase();
$fontsize = min($this->width, $this->height * 2) / (strlen($phrase));
$spacing = (integer) ($this->width * 0.9 / strlen($phrase));
is_dir($this->fonts) && $this->fonts = glob($this->fonts.'*.{ttf,otf}', GLOB_BRACE);
for ($i = 0, $strlen = strlen($phrase); $i < $strlen; $i++) {
$font = $this->fonts[array_rand($this->fonts)];
$color = imagecolorallocate($image, mt_rand(0, 160), mt_rand(0, 160), mt_rand(0, 160));
$angle = mt_rand(-30, 30);
$size = $fontsize / 12 * mt_rand(12, 14);
$box = imageftbbox($size, $angle, $font, $phrase[$i]);
$x = $spacing / 4 + $i * $spacing + 2;
$y = $this->height / 2 + ($box[2] - $box[5]) / 4;
imagefttext($image, $size, $angle, $x, $y, $color, $font, $phrase[$i]);
}
$this->image = $image;
$_SESSION['PAOPHP_CAPTCHA_KEY'] = $phrase;
return $this->image;
}
public static function Verify($str = null)
{
$key = $_SESSION['PAOPHP_CAPTCHA_KEY'];
if(!empty($_SESSION['PAOPHP_CAPTCHA_KEY']) && !empty($str) && strtolower($str) === strtolower($key)){
$_SESSION['PAOPHP_CAPTCHA_KEY'] = null;
unset($_SESSION['PAOPHP_CAPTCHA_KEY']);
return true;
}else{
return false;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
PHP微信公众号授权登陆,获取OpenID,昵称,头像相关信息完整源代码
共149个文件
gif:78个
js:32个
css:14个
需积分: 0 6 下载量 158 浏览量
2023-08-19
10:35:09
上传
评论
收藏 1.24MB ZIP 举报
温馨提示
PHP微信公众号授权登陆,获取OpenID,昵称,头像相关信息,完整源代码,只需修改几个配置信息就可以
资源推荐
资源详情
资源评论
收起资源包目录
PHP微信公众号授权登陆,获取OpenID,昵称,头像相关信息完整源代码 (149个子文件)
layui.css 78KB
layui.css 73KB
weui.min.css 49KB
admin.css 20KB
layer.css 14KB
layer.css 14KB
layui.mobile.css 10KB
laydate.css 7KB
laydate.css 7KB
Style.css 5KB
TmallStyle.css 2KB
code.css 1KB
code.css 1KB
style.css 154B
iconfont.eot 46KB
iconfont.eot 46KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
19.gif 3KB
66.gif 3KB
18.gif 3KB
46.gif 3KB
10.gif 3KB
28.gif 3KB
51.gif 3KB
57.gif 3KB
67.gif 3KB
0.gif 3KB
48.gif 3KB
43.gif 3KB
30.gif 2KB
61.gif 2KB
33.gif 2KB
69.gif 2KB
14.gif 2KB
47.gif 2KB
36.gif 2KB
49.gif 2KB
58.gif 2KB
6.gif 2KB
54.gif 2KB
53.gif 2KB
56.gif 2KB
62.gif 2KB
31.gif 2KB
55.gif 2KB
35.gif 2KB
15.gif 2KB
loading-2.gif 2KB
loading-2.gif 2KB
37.gif 1KB
68.gif 1KB
52.gif 777B
loading-1.gif 701B
loading-1.gif 701B
layui.js 284KB
layui.all.js 272KB
jquery-1.8.3.js 269KB
city1.js 134KB
jquery.js 95KB
jquery-weui.min.js 82KB
共 149 条
- 1
- 2
资源评论
网虫科技
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 毕业设计,基于PyQt5实现的可视化界面的Python车牌自动识别系统源码
- 26-朴素贝叶斯分类.rar
- 没有安Matlab 也可以 生成FIR抽头系数工具.py
- python烟花代码.rar
- 实验目的: 1.构建基于verilog语言的组合逻辑电路和时序逻辑电路; 2.掌握verilog语言的电路设计技巧 3.完成如
- 扩展卡尔曼滤波matlab仿真
- 3_base.apk.1
- 躺赢者PRO飞控常见典型问题合集(续一)无名小哥 余义 20240501待修
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功