- Impact
- 25
Hi all been doing my own captcha system and it seems to not want to work and i cannot figure out why.
Here is my captcha class:
The image file:
How i show it (this of course is not the whole file and yes i do start the session):
It is as if the image file doesn't pick up the session, i tried including the file with most things commented about bar echoing $rand1 and 2 and it shows the correct two strings, but it won't show on the image, the image is just my blank image with no letters/numbers . It can't be my templating functions can it since sessions are a global?
Here is my captcha class:
PHP:
class captcha_pxb
{
function generateRandom($length=6)
{
// first array = digits, second = lowercase, third uppercase
$_rand_src = array(
array(48,57),
array(97,122),
array(65,90)
);
$random_string = "";
for($i=0;$i<$length;$i++)
{
$i1=rand(0,sizeof($_rand_src)-1);
$random_string .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
}
return $random_string;
}
function make_session()
{
$_SESSION['captcha'] = $this->generateRandom(3);
$_SESSION['captcha_tmp'] = $this->generateRandom(3);
}
// check the wanted string against the one entered
function validate($wanted, $entered)
{
if ($wanted != $entered)
{
return false;
}
else
{
return true;
}
}
}
PHP:
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// lets make the captcha image from the blank image
$im = imagecreatefromjpeg("../../images/captcha_pxb.jpg");
// get the random strings from the session
$rand1 = $_SESSION['captcha'];
$rand2 = $_SESSION['captcha_tmp'];
ImageString($im, 5, 2, 2, $rand1[0]." ".$rand1[1]." ".$rand1[2]." ", ImageColorAllocate($im, 0, 0, 0));
ImageString($im, 5, 2, 2, " ".$rand2[0]." ".$rand2[1]." ".$rand2[2], ImageColorAllocate($im, 255, 0, 0));
Header('Content-type: image/jpeg');
imagejpeg($im, NULL, 100);
ImageDestroy($im);
How i show it (this of course is not the whole file and yes i do start the session):
PHP:
require_once(PXB_ROOT . '/includes/captchas/captcha_pxb.php');
$captcha = new captcha_pxb();
$captcha->make_session();
$guest_captcha = eval($templating->load('register', 'captcha_pxb'));
Last edited: