圖形數(shù)字驗(yàn)證代碼
更新時(shí)間:2006年10月09日 00:00:00 作者:
圖形數(shù)字驗(yàn)證代碼 Code: <?
/*
* Filename: authpage.php
*/
srand((double)microtime()*1000000);
//驗(yàn)證用戶輸入是否和驗(yàn)證碼一致
if(isset($_POST['authinput']))
{
if(strcmp($_POST['authnum'],$_POST['authinput'])==0)
echo "驗(yàn)證成功!";
else
echo "驗(yàn)證失??!";
}
//生成新的四位整數(shù)驗(yàn)證碼
while(($authnum=rand()%10000)<1000);
?>
<form action=authpage.php method=post>
<table>
請輸入驗(yàn)證碼:<input type=text name=authinput style="width: 80px"><br>
<input type=submit name="驗(yàn)證" value="提交驗(yàn)證碼">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=authimg.php?authnum=<? echo $authnum; ?>>
</table>
</form>
-------------------------------------------------------------------------------------------------------------
<?
/*
* Filename: authimg.php
*/
//生成驗(yàn)證碼圖片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
$im = imagecreate(58,28);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,68,30,$gray);
//將四位整數(shù)驗(yàn)證碼繪入圖片
imagestring($im, 5, 10, 8, $HTTP_GET_VARS['authnum'], $white);
for($i=0;$i<50;$i++) //加入干擾象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $gray);
}
ImagePNG($im);
ImageDestroy($im);
?>
相關(guān)文章
PHP4實(shí)際應(yīng)用經(jīng)驗(yàn)篇(7)
PHP4實(shí)際應(yīng)用經(jīng)驗(yàn)篇(7)...2006-10-10
php面向?qū)ο笕ヂ?(十一)__toString()用法 克隆對象 __call處理調(diào)用錯(cuò)誤
我們前面說過在類里面聲明“— ”開始的方法名的方法(PHP 給我們提供的),都是在某一時(shí)刻不同情況下自動(dòng)調(diào)用執(zhí)行的方法2009-09-09
php學(xué)習(xí)筆記之 函數(shù)聲明(二)
PHP可以在函數(shù)內(nèi)部再聲明函數(shù) 目的就是在函數(shù)內(nèi)部調(diào)用 用來幫助外部函數(shù)完成一些子功能2011-06-06

