2013-05-22 45 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