网络编程 
首页 > 网络编程 > 浏览文章

php实现点击可刷新验证码

(编辑:jimmy 日期: 2024/5/10 浏览:3 次 )

本文实例为大家分享了php点击可刷新验证码的具体代码,供大家参考,具体内容如下

验证码类文件 CreateImg.class.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, $y, $this->checkcode[$i], $bg_color); 
 } 
} 
function __destruct() 
{ 
 unset($this->width,$this->height,$this->codenum); 
} 
} 
"htmlcode">
<"htmlcode">
"content-type" content="text/html;charset=utf-8"> 
<script language="javascript"> 
function newgdcode(obj,url) { 
obj.src = url+ '"imgcode.php" alt="看不清楚,换一张" align="absmiddle" style="cursor: pointer;" onclick="javascript:newgdcode(this,this.src);" /> 
<form method="POST" name="form1" action="image.php"> 
<input type="text" name="test"> 
<br /> 
<input type="submit" name="submit" value="提交"> 
</form> 
</body> 
</head> 
</html> 

以上就是为大家介绍的php点击验证码即可刷新的全部代码,希望对大家的学习有所帮助。

上一篇:详解PHP数组赋值方法
下一篇:PHP中SSO Cookie登录分析和实现