无聊的验证码儿,直接调用
时间:2007-11-13
来源:互联网
比如说:把下面的代码保存为verifyimg.php
那么可以在模板页面或者html页面直接使用
<img src='verifyimg.php' id='verify' ><a href='#' onclick="document.getElementById('verify').src='verifyimg.php?No='+math.random();" >换个验证码</a>
生成的图片如下:
招初级phper的麻烦看下我的签名.看我写过的Class请点击这里
PHP代码:
<?php
session_start();
class image{
var $Width = 50;
var $Height = 20;
var $Text=array(
'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z');
function image(){
if(!empty($_GET['W'])){$this->Width=intval($_GET['W']);}
if(!empty($_GET['H'])){$this->Height=intval($_GET['H']);}
header("Content-type: image/png");
$IM = @imagecreate($this->Width,$this->Height); //创建一个空白图像
$RGB = $this->rand_color();
$Background_Color = imagecolorallocate($IM, $RGB[0], $RGB[1], $RGB[2]);//填充背景
//$RGB = $this->rand_color();
$RCO = imagecolorallocate($IM, $RGB[2], $RGB[1], $RGB[2]);
$RGB = $this->rand_color();
$RCT = imagecolorallocate($IM, $RGB[2], $RGB[1], $RGB[0]);
$Style = array($RCO,$RCO,$RCO,$RCO,$RCO,$RCO,$RCO,$RCO,$RCT,$RCT,$RCT,$RCT,$RCT,$RCT,$RCT,$RCT);
imagesetstyle($IM,$Style);
imageline($IM,0,0,$this->Width/rand(1,3),rand(1,$this->Height),IMG_COLOR_STYLED);//画一条线
imageline($IM,$this->Width/rand(1,4),0,$this->Width,$this->Height,IMG_COLOR_STYLED);//画一条线
imageline($IM,0,rand(0,$this->Height/2),$this->Width,rand(0,$this->Height),IMG_COLOR_STYLED);//画一条线
$TC = imagecolorallocate($IM,255,255,255);
$Text = $this->Text[rand(0,35)];
$_SESSION['_VERIFY']=$Text;
imagestring($IM,4,rand(0,$this->Width/4),rand(2,$this->Height/3),$Text,$TC);
//$RGB = $this->rand_color();
$TC = imagecolorallocate($IM,0,0,0);
$Text = $this->Text[rand(0,35)];
$_SESSION['_VERIFY'].=$Text;
imagestring($IM,4,$this->Width/2-5,$this->Heigth/2+rand(0,5),$Text,$TC);
$RGB = $this->rand_color();
$TC = imagecolorallocate($IM,$RGB[0],$RGB[2],$RGB[1]);
$Text = $this->Text[rand(0,35)];
$_SESSION['_VERIFY'].=$Text;
imagestring($IM,5,$this->Width-$this->Width/4,$this->Heigth/2+rand(1,7),$Text,$TC);
imagepng($IM);
imagedestroy($IM);
}
function rand_color(){
$Red = rand(0,255);
$Green = rand(0,255);
$Blue = rand(0,255);
return array($Red,$Green,$Blue);
}
}
new image();
?>
作者: lazy 发布时间: 2007-11-12
背景和三条线跟最后的一个字符是起干扰作用(不知道这样又没有效),当然也有可能干扰到用户...
作者: lazy 发布时间: 2007-11-12
作者: dujiangtao 发布时间: 2007-11-12
作者: hoday 发布时间: 2007-11-15

作者: luzhou 发布时间: 2007-11-15
作者: promaker 发布时间: 2007-11-15
无聊也别做无意义的事啊
作者: cyrus1986910 发布时间: 2007-11-15

作者: dzjzmj 发布时间: 2007-11-16
作者: chcn001 发布时间: 2007-11-16
作者: adleyliu 发布时间: 2007-11-16
引用:
原帖由 cyrus1986910 于 2007-11-15 15:05 发表用antispam就行了
无聊也别做无意义的事啊
作者: vsfree 发布时间: 2007-11-26
作者: CFC4N 发布时间: 2007-11-29

ding
study!
作者: 312344505 发布时间: 2008-01-10
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28