算数验证码
2016-04-09 00:00
155 查看
<?php
session_start();
getCode(100, 24);
function getCode($w, $h) {
$im = imagecreate($w, $h);
//imagecolorallocate($im, 14, 114, 180); // background color
$red = imagecolorallocate($im, 255, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$num1 = rand(1, 20);
$num2 = rand(1, 20);
$_SESSION['helloweba_math'] = $num1 + $num2;
$gray = imagecolorallocate($im, 118, 151, 199);
$black = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//画背景
imagefilledrectangle($im, 0, 0, 100, 24, $black);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $gray);
}
imagestring($im, 5, 5, 4, $num1, $red);
imagestring($im, 5, 30, 3, "+", $red);
imagestring($im, 5, 45, 4, $num2, $red);
imagestring($im, 5, 70, 3, "=", $red);
imagestring($im, 5, 80, 2, "?", $white);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
?>
session_start();
getCode(100, 24);
function getCode($w, $h) {
$im = imagecreate($w, $h);
//imagecolorallocate($im, 14, 114, 180); // background color
$red = imagecolorallocate($im, 255, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$num1 = rand(1, 20);
$num2 = rand(1, 20);
$_SESSION['helloweba_math'] = $num1 + $num2;
$gray = imagecolorallocate($im, 118, 151, 199);
$black = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//画背景
imagefilledrectangle($im, 0, 0, 100, 24, $black);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $gray);
}
imagestring($im, 5, 5, 4, $num1, $red);
imagestring($im, 5, 30, 3, "+", $red);
imagestring($im, 5, 45, 4, $num2, $red);
imagestring($im, 5, 70, 3, "=", $red);
imagestring($im, 5, 80, 2, "?", $white);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
?>
相关文章推荐
- 定义 Model兼容python2.x和python3.x
- Django 数据导入
- Django 多数据库联用
- Django创建超级管理员
- 用pyspider爬取乌云zone的贴子,上手非常地快速 动后河 (☭) [白帽子] | 2016-04-04 12:55
- Django QuerySet API
- 一套关于 Django 的笔试题
- 基于Spring4 Hibernate4 jersey实现rest风格系统
- 修改mysql数据库的用户名和密码
- 使用navicat建立与服务器的远程mysql连接
- MongoDB常用操作命令大全
- 安装完 MySQL 后必须调整的 10 项配置
- MySQL处理数据库和表的常用命令
- 修改mysql数据库为utf8
- Elasticsearch学习笔记
- elasticsearch结合spring springmvc jest 使用做成web架构
- elasticsearch java api 创建客户端连接(Transport Client)
- elasticsearch RESTful搜索引擎-安装
- AngularJS 源码分析3
- AngularJS 源码分析4