Page 1 of 1

image captcha problem

Posted: Thu Jun 17, 2010 8:04 am
by adsegzy
Hello here,

please am having image captcha problem. I uploaded some images on my site to be used as captcha. the name i used to save each image is the word on it. for example, on the image which i saved with the name 'FOOD' has the word FOOD written on it. So the guest needs to write the name on the image into a field named 'capname'. This is how i randomly select the images;

Code: Select all

<?php
$imglist='';
$img_folder = "captcha/"; #Don't forget to put / in the end#

mt_srand((double)microtime()*1000);

//using the directory class
$imgs = dir($img_folder);

//reads all the files from the folder and checks if they are images and then ads them to a list
while ($file = $imgs->read()) {
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
$imglist .= "$file ";

} closedir($imgs->handle);

//put all images into an array
$imglist = explode(" ", $imglist);
$no = sizeof($imglist)-2;

//generate a random number between 0 and the number of images
$random = mt_rand(0, $no);
$image = $imglist[$random];
$picname= $image;
$imgname=$picname.'png'
?>
this is how i verify the entry

Code: Select all

if($capname != $imgname)
echo "<span class='style3'>You've entered wrong word in the Picture, retry.</span><br>";
but even if the entry is correct, it will still echo You've entered wrong word in the Picture, retry.
what can i do. or do you have any other way of echoing out the images and verifying them.

Re: image captcha problem

Posted: Thu Jun 17, 2010 12:28 pm
by hypedupdawg
I think what is happening is that the inuput text (e.g. "foo") is being checked against the full filename (e.g. "./images/foo.jpg") or some variant, and this is why it's not working. You could try saving just the filename in another array, or you could use a regex expression to check the string using the preg_match() function.

Re: image captcha problem

Posted: Thu Jun 17, 2010 10:15 pm
by Phoenixheart
Just curious, why are you doing captcha this way? If the file name is FOOD, and the captcha code is FOOD, then where is the expected security?