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

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
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

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

Post 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? :?:
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

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

Post 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.
User avatar
mirra1515
Forum Commoner
Posts: 29
Joined: Fri Apr 25, 2008 3:17 am

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

Post 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.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

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

Post 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
LSJason
Forum Commoner
Posts: 45
Joined: Mon May 12, 2008 4:43 pm

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

Post 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.
Mr.RED
Forum Newbie
Posts: 8
Joined: Sat May 31, 2008 1:23 pm

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

Post by Mr.RED »

Normally enabling GD is as simple as un commenting a line in php.ini for the GD library.
LSJason
Forum Commoner
Posts: 45
Joined: Mon May 12, 2008 4:43 pm

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

Post by LSJason »

Not if GD itself isn't installed on the server.
Post Reply