您好,欢迎访问一九零五行业门户网

很实用的一个php验证码类_PHP教程

一个比较实用的php图形验证码生成类,调用方法也很简单的,有需要的朋友可以参考一下。
 代码如下 复制代码
width=$width;
  $this->height=$height;
  $this->codenum=$codenum;
  $this->checkcode=$this->createcheckcode();
 }
function getcreateimage(){
  $this->getcreateimage();
  $this->outputtext();
  $this->setdisturbcolor();
  $this->outputimage();
 }
 function getcheckcode(){
  return $this->checkcode;
 }
private function getcreateimage(){
  $this->image=imagecreatetruecolor($this->width,$this->height);
  $black=imagecolorallocate($this->image,255,255,255,0);
  $border=imagecolorallocate($this->image,255,255,255,255);
  imagefilledrectangle($this->image,0,0,$this->width-1,$this->height-1,$border);
 }
 private function createcheckcode(){
  for($i=0;$icodenum;$i){
   $number=rand(0,2);
   switch($number){
    case 0:
     $rand_number=rand(48,57);//数字
     break;
    case 1:
     $rand_number=rand(65,90);//大写字母
     break;
    case 2:
     $rand_number=rand(97,122);
     break;
   }
   $asc=sprintf(%c,$rand_number);
   $asc_number=$asc_number.$asc;
  }
  return $asc_number;
 }
 private function setdisturbcolor(){
  for($i=0;$i   $color=imagecolorallocate($this->image,255,255,255);
   imagesetpixel($this->image,rand(1,$this->width-2),rand(1,$this->height-2),$color);
  }
 }
 private function outputimage(){
  if(imagetypes()&img_gif){
   header(content_type:image/gif);
   imagegif($this->image);
  }elseif(imagetypes()&img_jgp){
   header(content_type:image/jpeg);
   imagejpeg($this->image,,0.5);
  }else{
   die(php不支持图像创建);
  }
 }
 function __destruct(){
  imagedestroy($this->image);
 }
}
?>
http://www.bkjia.com/phpjc/629693.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/629693.htmltecharticle一个比较实用的php图形验证码生成类,调用方法也很简单的,有需要的朋友可以参考一下。 代码如下 复制代码 ?php classimagecode{ private $widt...
其它类似信息

推荐信息