這幾天為學院的Flash_Dv大賽做了一個投票系統(tǒng)。
為了盡量減少漏洞,我上網查了一下關于投票系統(tǒng)的漏洞問題。
從下面的文章中我才知道驗證碼的重要性:
http://blog.csdn.net/fiso/archive/2004/11/23/192855.aspx這是關于驗證的一點介紹:
??????? 目前,不少網站為了防止用戶利用機器人自動注冊、登錄、灌水,都采用了驗證碼技術。所謂驗證碼,就是將一串隨機產生的數(shù)字或符號,生成一幅圖片,圖片里加上一些干擾象素(防止OCR),由用戶肉眼識別其中的驗證碼信息,輸 入表單提交網站驗證,驗證成功后才能使用某項功能。
PHP代碼實現(xiàn):
<?php
//生成驗證碼圖片
Header("Content-type: image/PNG");?
srand((double)microtime()*1000000);
$authnum=rand(1000,9999);
setcookie("authnum",$authnum);//用cookie保存生成四位整數(shù)
$im = imagecreate(62,20);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,0,0,$gray);
//將四位整數(shù)驗證碼繪入圖片
imagestring($im, 5, 10, 3, $authnum, $black);
for($i=0;$i<200;$i++) //加入干擾象素
{
??? $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
??? imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>
posted on 2006-11-06 23:58
beyonlin 閱讀(673)
評論(0) 編輯 收藏 引用 所屬分類:
php之路