本文实例讲述了PHP实现简单实用的验证码类。分享给大家供大家参考。具体如下:

<"Content-type: image/png");
}
/**
  * 产生验证码
  */
private function createCode()
{
  $this->checkcode = strtoupper(substr(md5(rand()),0,$this->codenum));
}
/**
  * 产生验证码图片
  */
private function createImage()
{
  $this->checkimage = @imagecreate($this->width,$this->height);
  $back = imagecolorallocate($this->checkimage,255,255,255); 
  $border = imagecolorallocate($this->checkimage,0,0,0); 
  imagefilledrectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$back); // 白色底
  imagerectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$border);  // 黑色边框
}
/**
  * 设置图片的干扰像素 
  */
private function setDisturbColor()
{
  for ($i=0;$i<=200;$i++)
  {
  $this->disturbColor = imagecolorallocate($this->checkimage, rand(0,255), rand(0,255), rand(0,255));
  imagesetpixel($this->checkimage,rand(2,128),rand(2,38),$this->disturbColor);
  }
}
/**
  *
  * 在验证码图片上逐个画上验证码
  *
  */
private function writeCheckCodeToImage()
{
  for ($i=0;$i<$this->codenum;$i++)
  {
  $bg_color = imagecolorallocate ($this->checkimage, rand(0,255), rand(0,128), rand(0,255));
  $x = floor($this->width/$this->codenum)*$i;
  $y = rand(0,$this->height-15);
  imagechar ($this->checkimage, rand(5,8), $x+5, $y, $this->checkcode[$i], $bg_color);
  }
}
function __destruct()
{
  unset($this->width,$this->height,$this->codenum,$this->session_flag);
}
}
?>

希望本文所述对大家的php程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。