Page 1 of 1

Security Image, CAPTCHA [solved]

Posted: Wed Mar 15, 2006 8:57 pm
by anthony88guy
So I have a file called image.php, where the CAPTCHA is generated. Now my problem is how to communicate between image.php and the actual page. The CATCHA "code" is stored in the database or in $_SESSIONS a variable. But when I tired to run a MySQL query in the image.php file it doesn’t work, I could be doing something wrong.

Posted: Wed Mar 15, 2006 9:02 pm
by feyd
Although I love a good mystery, this isn't very helpful when it's specific to code. Post some.

Posted: Wed Mar 15, 2006 9:17 pm
by anthony88guy
image.php:

Code: Select all

<?php
header("Content-type: image/png");

$image['height'] = 20;
$image['width'] = 65;
$img = imagecreate($image['width'], $image['height']);

$image['bordercolor'] = imagecolorallocate($img, 102, 102, 102);
$image['borderwidth'] = 2;
$image['bgcolor'] = imagecolorallocate($img, 85, 85, 85);
$image['textcolor'] = imagecolorallocate($img, 204, 204, 204);
$image['textsize'] = 10;
$image['textangle'] = rand(-7,7);
$image['text'] = substr(md5(rand(1,1000)),27); //stored in sessions var and/or database

imagefill($img, 0, 0, $image['bordercolor']);
imagefilledrectangle($img, $image['borderwidth'], $image['borderwidth'], $image['width']-$image['borderwidth'], $image['height']-$image['borderwidth'], $image['bgcolor']); 
imagettftext ($img, $image['textsize'], $image['textangle'], rand(5,20), 15, $image['textcolor'], '/fonts/tahomabd.ttf', $image['text']); 

imagepng($img);
?>

Posted: Wed Mar 15, 2006 9:26 pm
by feyd
where's the MySQL stuff?

Posted: Wed Mar 15, 2006 9:37 pm
by anthony88guy
My bad, I figured it out though. I forgot that as along as nothing is being outputted to the browser header() doesnt have to be at the top, so I did my MySQL before the header and all worked well.