2013-05-22 91 views
0

我在CodeIgniter中完成我的項目。我正在嘗試在索引文件中調用captcha.php文件。此captcha文件位於文件夾文件中。目前,驗證碼圖片未查看。我需要在圖像中顯示隨機數字。codeigniter中的圖像驗證碼

captcha.php

<?php 
session_start(); 

$string = ''; 

for ($i = 0; $i < 5; $i++) { 
    $string .= chr(rand(97, 122)); 
} 

$_SESSION['random_number'] = $string; 

$dir = 'fonts/'; 

$image = imagecreatetruecolor(165, 50); 

// random number 1 or 2 
$num = rand(1,2); 
if($num==1) 
{ 
    $font = "PT_SANS-BOLD_1.TTF"; // font style 
} 
else 
{ 
    $font = "PT_SANS-ITALIC_1.TTF";// font style 
} 

// random number 1 or 2 
$num2 = rand(1,2); 
if($num2==1) 
{ 
    $color = imagecolorallocate($image, 113, 193, 217);// color 
} 
else 
{ 
    $color = imagecolorallocate($image, 163, 197, 82);// color 
} 

$white = imagecolorallocate($image, 255, 255, 255); // background color white 
imagefilledrectangle($image,0,0,399,99,$white); 

imagettftext ($image, 30, 0, 10, 40, $color, $dir.$font, $_SESSION['random_number']); 

header("Content-type: image/png"); 
imagepng($image); 

?> 

in html file 

<img src="<?= base_url();?>files/captcha.php" alt="" id="captcha" /> 
+0

是這codeigniter captcha或自定義captcha? –

+0

jquery captcha [鏈接](http://www.99points.info/2010/08/ajax-stylish-captcha-and-contact-form-using-jquery-and-php/) – sangeetha

+0

從此鏈接我拿了captcha – sangeetha

回答

0

這不是一個回答你的問題,但替代,你可以選擇。

如此多的驗證碼腳本已經可用,可能您可以使用其中的一部分而不是再次編碼。

檢查this

如果你去了這個選項,那麼請務必注意字體被放置在正確的地方。

+0

你說什麼,我都試過它仍然沒有顯示它的圖像內容 – sangeetha

+0

像這樣,我只需要給予 – sangeetha