2013-11-22 12 views
0

我的驗證碼不工作,它只顯示一個方形的縮略圖,當我在瀏覽器上啓動它時,你能發現問題嗎?我感謝你的幫助的感謝我的驗證碼不工作,它只顯示一個方形縮圖

<?php 

session_start(); 
//Settings: You can customize the captcha here 
$image_width = 120; 
$image_height = 40; 
$characters_on_image = 6; 
$font = './monofont.ttf'; 

//The characters that can be used in the CAPTCHA code. 
//avoid confusing characters (l 1 and i for example) 
$possible_letters = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ'; 
$random_dots = 0; 
$random_lines = 20; 
$captcha_text_color="0x142864"; 
$captcha_noice_color = "0x142864"; 

$code = ''; 


$i = 0; 
while ($i < $characters_on_image) { 
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1); 
$i++; 
} 


$font_size = $image_height * 0.75; 
$image = @imagecreate($image_width, $image_height); 


/* setting the background, text and noise colours here */ 
$background_color = imagecolorallocate($image, 255, 255, 255); 

$arr_text_color = hexrgb($captcha_text_color); 
$text_color = imagecolorallocate($image, $arr_text_color['red'], 
     $arr_text_color['green'], $arr_text_color['blue']); 

$arr_noice_color = hexrgb($captcha_noice_color); 
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'], 
     $arr_noice_color['green'], $arr_noice_color['blue']); 


/* generating the dots randomly in background */ 
for($i=0; $i<$random_dots; $i++) { 
imagefilledellipse($image, mt_rand(0,$image_width), 
mt_rand(0,$image_height), 2, 3, $image_noise_color); 
} 


/* generating lines randomly in background of image */ 
for($i=0; $i<$random_lines; $i++) { 
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height), 
mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color); 
} 


/* create a text box and add 6 letters code in it */ 
$textbox = imagettfbbox($font_size, 0, $font, $code); 
$x = ($image_width - $textbox[4])/2; 
$y = ($image_height - $textbox[5])/2; 
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code); 


/* Show captcha image in the page html page */ 
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow 
imagejpeg($image);//showing the image 
imagedestroy($image);//destroying the image instance 
$_SESSION['6_letters_code'] = $code; 

function hexrgb ($hexstr) 
{ 
    $int = hexdec($hexstr); 

    return array("red" => 0xFF & ($int >> 0x10), 
       "green" => 0xFF & ($int >> 0x8), 
       "blue" => 0xFF & $int); 
} 
?> 

我的圖形驗證碼無法正常工作,它只能說明當我啓動它在瀏覽器上,你可以發現問題的正方形縮略圖?我感謝您的幫助,謝謝,

enter image description here

+0

它在行231 – adeneo

+0

根據你的代碼,你在'captcha_code_file.php'文件中有實際的驗證碼,所以你發佈的所有代碼都是不相關的。 – eis

+0

eis我編輯了我的問題,並把captcha_code_file.php你能看到最新的問題? –

回答

0

你可能沒有monofont.ttf在同一目錄作爲您的驗證碼腳本位置。請確保它在那裏。

如果你沒有這個字體文件,我發現這個鏈接後,快速谷歌搜索你可以下載它。 http://trac.assembla.com/webam/export/90/captcha/monofont.ttf

下載該文件並將其與您的captcha php文件放在同一目錄中。我已經嘗試過了,它工作正常

See a screenshot of it working on my sand box

另一種可能是你沒有安裝GD做。取決於你的系統上運行:

基於Debian的系統:基於

apt-get install php5-gd 

紅色帽子:

yum installphp5-gd 

可能會解決你的問題也是如此。

相關問題