image captcha problem

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
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

image captcha problem

Post 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.
User avatar
hypedupdawg
Forum Commoner
Posts: 74
Joined: Sat Apr 10, 2010 5:21 am

Re: image captcha problem

Post 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.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: image captcha problem

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