php 数学运算验证码实现代码
2018-10-12 13:53
756 查看
<?php
//-------------------------------------
// 文件说明:数学运算验证码
// 文件作者:Jesse Lee
// 最后更新:2008-09-07
//-------------------------------------
session_start();
$sessionvar = 'vdcode'; //Session变量名称
$width = 150; //图像宽度
$height = 20; //图像高度
$operator = '+-*'; //运算符
$code = array();
$code[] = mt_rand(1,9);
$code[] = $operator{mt_rand(0,2)};
$code[] = mt_rand(1,9);
$code[] = $operator{mt_rand(0,2)};
$code[] = mt_rand(1,9);
$codestr = implode('',$code);
eval("\$result = ".implode('',$code).";");
$code[] = '=';
$_SESSION[$sessionvar] = $result;
$img = ImageCreate($width,$height);
ImageColorAllocate($img, mt_rand(230,250), mt_rand(230,250), mt_rand(230,250));
$color = ImageColorAllocate($img, 0, 0, 0);
$offset = 0;
foreach ($code as $char) {
$offset += 20;
$txtcolor = ImageColorAllocate($img, mt_rand(0,255), mt_rand(0,150), mt_rand(0,255));
ImageChar($img, mt_rand(3,5), $offset, mt_rand(1,5), $char, $txtcolor);
}
for ($i=0; $i<100; $i++) {
$pxcolor = ImageColorAllocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
ImageSetPixel($img, mt_rand(0,$width), mt_rand(0,$height), $pxcolor);
}
header('Content-type: image/png');
ImagePng($img);
?>
您可能感兴趣的文章:
相关文章推荐
- php 数学运算验证码实现代码
- php数字运算验证码的实现代码
- php数字运算验证码的实现代码
- 后台登录(包含验证码)的php代码实现
- 用PHP实现的四则运算表达式计算实现代码
- php实现可运算的验证码
- 【代码实现】PHP生成各种随机验证码
- PHP使用数组实现矩阵数学运算的方法示例
- 【代码实现】PHP生成各种随机验证码
- php的chr和ord函数实现字符加减乘除运算实现代码
- php实现的数字验证码及数字运算验证码
- php验证码实现代码(3种)
- PHP 验证码的实现代码
- PHP 实现后缀表达式(接受四则运算字符串,输出计算结果,附代码)
- PHP 验证码的实现代码
- 一个简单的PHP验证码实现代码
- php验证码实现代码
- php实现加减法验证码代码
- php的chr和ord函数实现字符加减乘除运算实现代码
- php实现可运算的验证码