PHP開發(fā)簡單圖書後臺系統(tǒng)建立登入驗證碼
在登入介面會使用驗證碼功能,
這裡我們建立一個簡單的驗證碼檔案。
在我們PHP中文網(wǎng) "?PHP開發(fā)之登入註冊教學(xué)「 的 「PHP開髮用戶登入模組製作簡單驗證碼」章節(jié)中介紹了一種簡單驗證碼的製作,大家可以參考。
建立一個verify.php文件,方便後面的呼叫
這裡設(shè)定一個4位數(shù)的驗證碼
<?php session_start(); srand((double)microtime()*1000000); while(($authnum=rand()%10000)<1000);//生成四位隨機整數(shù)驗證碼 $_SESSION['auth']=$authnum; //生成驗證碼圖片 Header("Content-type: image/PNG"); $im = imagecreate(55,18); $red = ImageColorAllocate($im, 255,0,0); $white = ImageColorAllocate($im, 200,200,100); $gray = ImageColorAllocate($im, 250,250,250); $black = ImageColorAllocate($im, 120,120,50); imagefill($im,60,20,$gray); //將四位整數(shù)驗證碼繪入圖片 //位置交錯 for ($i = 0; $i < strlen($authnum); $i++) { $i%2 == 0?$top = -1:$top = 3; imagestring($im, 6, 13*$i+4, 1, substr($authnum,$i,1), $white); } for($i=0;$i<100;$i++) //加入干擾象素 { imagesetpixel($im, rand()%70 , rand()%30 , $black); } ImagePNG($im); ImageDestroy($im); ?>