[eluser]Volkscom[/eluser]
Hi,
I'm trying to include my own captcha generation function in codeIgniter.In that I'm using session for storing the code.But it is not working properly
My controller contains:
class Reg_controller extends Controller{
function index(){
$this->load->library('session');
$this->load->helper(array("form","html","url",'email'));
$this->load->library('form_validation');
$this->load->language('registration');
$this->load->view('tocheck');
}
function captchakey(){
$this->load->helper(array("form","html","url"));
include('/function_captcha.php');
print_captcha("5");
}
}
view contains:
<?php echo form_fieldset('verification Details');?>
<table>
<tr><th colspan="2" align="center">
<?php echo form_label('Enter Verification Code');?>
</th></tr>
<tr><td colspan="2" align="center">
<?php
/*$image_properties = array('src' => 'system/application/libraries/Gen_captcha.php',
'alt' => 'Verification code',
'width' => '120',
'height' => '40',
"class"=>"frm"
);
*/
/*$image_properties = array('src' =>base_url().'index.php/reg_controller/captchakey',
'alt' => 'Verification code',
'width' => '120',
'height' => '40',
"class"=>"frm"
);
*/
echo "<a href='".base_url()."index.php/reg_controller/captchakey"."'> <font color='red'>hi</font></a>";
//echo img($image_properties);
?>
nbdbfjdj
</td></tr>
<tr><td>
<?php echo form_label('Enter code');?><span class="star">*</span></td><td>
<?php echo form_input( array('name'=> 'code',
'id'=>'code',
"class"=>"frm"
));?><?php echo"<input type='hidden' name='utype' value='R' >";?>
</td></tr>
</table>
<?php echo form_fieldset_close();?>
function.captcha.php contains
<?php
session_start();
function print_captcha($length = 5)
{
$src = 'abcdefghjkmnpqrstuvwxyz123456789';
$srclen = strlen($src)-1;
// what font file to use
$font = '../../fonts/AppleGaramond.ttf';
// font size range, angle range, character padding
$min_font_size = 10;
$max_font_size = 20;
$min_angle = -15;
$max_angle = 15;
// font character padding
$char_padding = 1;
$data = array();
$image_width = $image_height = 0;
// write some data to the temp file
// build the data array of the characters, size, placement, etc.
$_SESSION['captcha'] = '';
for ($i=0; $i < $length; $i++)
{
$char = strtoupper(substr($src, mt_rand(0, $srclen), 1));
$_SESSION['captcha'] .= "$char";
$size = mt_rand($min_font_size, $max_font_size);
$angle = mt_rand($min_angle, $max_angle);
$bbox = imagettfbbox($size, $angle, $font, $char);
$char_width = max($bbox[2],$bbox[4]) - min($bbox[0],$bbox[6]);
$char_height = max($bbox[1],$bbox[3]) - min($bbox[7],$bbox[5]);
$image_width += $char_width + $char_padding;
$image_height = max($image_height, $char_height);
$data[] = array('char' => $char, 'size' => $size, 'angle' => $angle, 'height' => $char_height, 'width' => $char_width,);
}
}
If anybody Knows how to do this.Please Help me
Thanks In Advance!...