Page 1 of 1

CAPTCHA Program doesn't work on web but works on PC

Posted: Sat May 31, 2008 12:06 am
by mirra1515
I have developed a simple captcha program with the help of some online resources and it works great on my local computer using apache.

The problem is that once I upload it to a server it stops working. I imagine this has something to do with headers...but I am not sure. In anycase, here's my code:

Display page uses this simple command:

Code: Select all

<img src="http://www.mysite.com/scripts/php_captcha.php">
php_captcha.php looks like:

Code: Select all

<?php
session_start();
 
$RandomStr = md5(microtime());// md5 to generate the random string
 
$ResultStr = substr($RandomStr,0,5);//trim 5 digit 
 
$NewImage = imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground 
 
$LineColor = imagecolorallocate($NewImage,233,239,239);//line color 
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white
 
imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image 
imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image 
 
imagestring($NewImage, 5, 20, 10, $ResultStr, $TextColor);// Draw a random string horizontally 
 
$_SESSION['key'] = $ResultStr;// carry the data through session
 
header("Content-type: image/jpeg");// out out the image 
 
imagejpeg($NewImage);//Output image to browser 
 
?>
The image "img.jpg" is definately located in the same folder as "php_captcha.php", so that can't be the problem.

Even the session variable stored to in php_captcha isn't being stored to on the web...leading me to believe that the php_captcha.php program is never run properly.

Any ideas on what could be causing this setup to work on my computer with Apache and yet fail when uploaded to a web server? :?:

Re: CAPTCHA Program doesn't work on web but works on PC

Posted: Sat May 31, 2008 12:12 am
by nowaydown1
Are you sure GD is actually installed? If you have display_errors turned off and GD isn't installed that might do it. Do a function_exists on imagecreatefromjpeg or dump phpinfo() and make sure the extension is enabled.

Re: CAPTCHA Program doesn't work on web but works on PC

Posted: Sat May 31, 2008 7:37 pm
by mirra1515
I don't think GD is installed on this server. That would explain why this script wouldn't work. I didn't know you needed something extra installed to run these commands, that is enlightening.

How would I go about installing GD on the server?

BTW: Thanks a bunch for your post, very interesting, and probably whats wrong.

Re: CAPTCHA Program doesn't work on web but works on PC

Posted: Sat May 31, 2008 7:54 pm
by nowaydown1
How you go about installing GD will depend on OS. There's specifics available at:

http://us2.php.net/manual/en/image.installation.php

Re: CAPTCHA Program doesn't work on web but works on PC

Posted: Sat May 31, 2008 9:24 pm
by LSJason
You will have to recompile PHP in most cases to install GD. If you don't have experience with that kind of thing, I highly suggest hiring a professional as opposed to doing it yourself.

Re: CAPTCHA Program doesn't work on web but works on PC

Posted: Sun Jun 01, 2008 5:47 am
by Mr.RED
Normally enabling GD is as simple as un commenting a line in php.ini for the GD library.

Re: CAPTCHA Program doesn't work on web but works on PC

Posted: Sun Jun 01, 2008 8:01 am
by LSJason
Not if GD itself isn't installed on the server.