php代碼
<?php
class Captcha_code
{
var $width=
var $num=
var $height=
var $name=
public function __construct($conf="")
{
if($conf!="")
{
foreach($conf as $key=>$value)
{
$this
}
}
}
function show()
{
Header("Content
/*
* 初始化
*/
$border =
$how = $this
$w = $this
$h = $this
$fontsize =
$alpha = "abcdefghijkmnopqrstuvwxyz"; //驗證碼內容
$number = "
$randcode = ""; //驗證碼字符串初始化
srand((double)microtime()*
$im = ImageCreate($w
/*
* 繪制基本框架
*/
$bgcolor = ImageColorAllocate($im
ImageFill($im
if($border)
{
$black = ImageColorAllocate($im
ImageRectangle($im
}
/*
* 逐位產生隨機字符
*/
for($i=
{
$alpha_or_number = mt_rand(
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(
$code = substr($str
$j = !$i ?
$color
ImageChar($im
$randcode
}
/*
* 添加干擾
*/
for($i=
{
$color
ImageArc($im
}
for($i=
{
$color
ImageSetPixel($im
}
//把驗證碼字符串寫入session
//$this
$_SESSION[$this
/*繪圖結束*/
Imagegif($im);
ImageDestroy($im);
/*繪圖結束*/
}
}
?>
調用php代碼
function verify_image() {
$conf[
$this
$this
$yzm_session = $this
echo $yzm_session;
}
html代碼
<dl>
<dt>驗證碼
<dd>
<input type="text" name="verify_text" id="verify_text" class="yzma" value="">
<img src="/user/verify_image" alt="驗證碼" id="verify_code" class="yz_img" />
<a href="javascript:changeCode();" class="change_yz">換一張</a>
</dd>
<dd class="tips_wrong"><b>驗證碼不正確</b></dd>
<dd class="tips_correct"></dd>
</dl>
js代碼
<script type="text/javascript">
function changeCode(){
FS
}
</script>
From:http://tw.wingwit.com/Article/program/PHP/201311/21333.html