驗證碼,是一種區分用戶是計算機和人的公共全自動程序,在captcha測試中,作為服務器的計算機會自動生成一個問題由用戶來解答,這個問題可以由計算機生成并評判,但是必須只有人類才能解答,由于計算機無法解答captcha的問題,所以回答出問題的用戶就可以被認為是人類,php實例代碼如下:
- */
- session_start();
- $string = null;
- $im = imagecreatetruecolor(60,25); //創建真彩圖60*25
- $bg = imagecolorallocate($im,255,255,255);//白色背景
- imagefill($im,0,0,$bg);填充白色
- $x = 5;//
- $y = 0;//文字坐標
- for($i=0 ; $i<4 ;$i++)
- {//開源代碼Vevb.com
- $char = mt_rand(0,9);
- $string .=$char;
- $y = mt_rand(0,10);
- $ccolor = imagecolorallocate($im,mt_rand(0,230),mt_rand(0,230),mt_rand(0,230));
- imagechar($im,6,$x,$y,$char,$ccolor);//填充文字
- $x += mt_rand(10,15);
- }
- for($i=0 ;$i
- {
- $x1 = mt_rand(0,80);
- $x2 = mt_rand(0,80);
- $y1 = mt_rand(0,30);
- $y2 = mt_rand(0,30);
- $x2 = $x1 +mt_rand(1,5);
- $y2 = $y1 +mt_rand(1,5);
- $lc = imagecolorallocate($im,mt_rand(0,230),mt_rand(0,230),mt_rand(0,230));
- imageline($im,$x1,$y1,$x2,$y2,$lc);//填充線條
- }
- $_session['code'] = md5($string);
- header("content-type:image/jpeg");
- imagepng($im);
- imagedestroy($im);
新聞熱點
疑難解答