备注:将公共页面加入ssion_start();
港版美素奶粉真假
<?php
ssion_start();
ini_t(‘display_errors’, ‘off’);
class ccheckcodefile
{
//验证码位数 www.2cto.com
var $mcheckcodenum = 4;
//产生的验证码
var $mcheckcode = ”;
//验证码的图片
var $mcheckimage = ”;
//干扰像素
var $mdisturbcolor = ”;
//验证码的图片宽度
var $mcheckimagewidth = ’80’;
//验证码的图片宽度
var $mcheckimageheight = ’20’;
//输出头
function outfileheader()
{
header (“content-type: image/png”);
}
//产生验证码
function createcheckcode()
{
//$this->mcheckcode = strtoupper(substr(md5(rand()),0,$this->mcheckcodenum));
$this->mcheckcode = strtoupper(substr(rand(0,9999999999),0,$this->mcheckcodenum));
ssion_cache_expire(60);
ssion_start();
$_ssion[“code_str”] = $this->mcheckcode;
return $this->mcheckcode;
}
//产生验证码图片
function createimage()
{
$this->mcheckimage = @imagecreate ($this->mcheckimagewidth,$this->mcheckimageheight);
imagecolorallocate ($this->mcheckimage, 255, 255, 255);
return $this->mcheckimage;
}
//设置图片的干扰像素
function tdisturbcolor()
{
for ($i=0;$i<=128;$i++)
{
$this->mdisturbcolor = imagecolorallocate ($this->mcheckimage, rand(0,255), rand(0,255), rand(0,255));
imagetpixel($this->mcheckimage,rand(1,100),rand(1,100),$this->mdisturbcolor);
}
}
//设置验证码图片的大小\宽\高
function tcheckimagewh($width,$height)
{
if($width==”||$height==”)return fal;
$this->mcheckimagewidth = $width;
$this->mcheckimageheight = $height;
return true;
}
//在验证码图片上逐个画上验证码
function writecheckcodetoimage()
{
for ($i=0;$i<=$this->mcheckcodenum;$i++)
{
$bg_color = imagecolorallocate ($this->mcheckimage, rand(0,255), rand(0,255), rand(0,255));
$x = floor($this->mcheckimagewidth/$this->mcheckcodenum)*$i;
$y = rand(0,$this->mcheckimageheight-15);
imagechar ($this->胜利者英文;mcheckimage, 5, $x, $y, $this->mcheckcode[$i], $bg_color);
}
}
//输出验证码图片
function outcheckimage()
{
$this ->outfileheader();
刨根问底的近义词 $this ->createcheckcode();
$this ->createimage();
$this ->tdisturbcolor();
$this ->writecheckcodetoimage();
imagepng($this->mcheckimage);
imagedestroy($this->mcheckimage);
}
}
$c_check_code_image = new ccheckcodefile();
//$c_check_code_image ->tcheckimagewh(100,50);//设置显示验证码图片的尺寸
$c_check_code_image->outcheckimage();
?>
使用方法:
<tr>
<td alig少先队什么时候改为少年先锋队n=”center” valign=”middle”>验证码</td>
<td align=”center” valign=”middle”><input name=”number” type=”text” style=”width:80px;”>
<img src=”code.php” id=”yzm” onclick=”this.src=’code.php?abc=’+math.random()” alt=”图片看不清?点击重新得到验证码” style=”cursor:hand;” />
</td>
</tr>
验证是否正确
ssion_start();
甘肃医药
if($_post[“number”] == $_ssion[“code_str”]){
// echo(“验证码正确”);
}el{
echo “
<script>
var s=10;
function ok()
{
s–;
document.getelementbyid(‘tips’).innerhtml=s;
if(s==0)
{
cleartimeout(t);
history.go(-1);
}
}
var t=tinterval(‘ok()’,1000);
</script>
” . “请输入的验证码,请重新输入<span id=’tips’></span>秒之后,将为您跳转到<a href=\”javascript:history.go(-1)\”>上一页</a>”;
}
摘自 https://itsafe.org/?p=384
本文发布于:2023-04-07 05:50:13,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/ec0f88fbccd51f6dbd9a885c9cbcb430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP中验证码类及使用方法.doc
本文 PDF 下载地址:PHP中验证码类及使用方法.pdf
留言与评论(共有 0 条评论) |