[eluser]Dandy_andy[/eluser]
I am trying to modify a simple script that generates a captcha so that when it is called for, it generates the image within a portion of the view. I am confused about how to do this using the MVC approach. I have a library file called 'captcha.php' which is a very slightly modified script that I have used before and which I copied from a source on the net:-
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Captcha {
function captcha()
{
$string = '';
for ($i = 0; $i < 8; $i++) {
$string .= chr(rand(97, 122));
}
$code['rand_code'] = $string;
$dir = '';
$image = imagecreatetruecolor(170, 60);
$black = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 200, 100, 90); // red
$white = imagecolorallocate($image, 255, 255, 255);
$lgrey = imagecolorallocate($image, 238, 238, 238);
imagefilledrectangle($image,0,0,200,100,$lgrey);
imagettftext($image, 30, 5, 10, 40, $color, $dir."font.ttf", $code['rand_code']);
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
}
?>
Before using this in Codeigniter, the script was run directly (outside of a function) by loading it as a image using the HTML
Code:
<img src="captcha.php" alt="" />
but I am trying to work this within the MVC method. How can I pass the generated PNG image without using a database or generating an image that I have to store and then retrieve from the viewer? At the moment, the captcha is generated as soon as the library is loaded and takes control.