Security Image, CAPTCHA [solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Security Image, CAPTCHA [solved]

Post 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.
Last edited by anthony88guy on Wed Mar 15, 2006 9:37 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Although I love a good mystery, this isn't very helpful when it's specific to code. Post some.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post 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);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where's the MySQL stuff?
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post 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.
Post Reply