...

View Full Version : Captcha



westmatrix99
02-25-2007, 02:43 PM
How to create a captcha, have tried lines of captcha code but images are always blank.
So how do I do this?

vinyl-junkie
02-25-2007, 03:18 PM
Are you trying to incorporate someone else's captcha code into one of your existing web pages, or what? Post your code. It's impossible to offer you any real help without that.

westmatrix99
02-25-2007, 03:26 PM
I am using a tutorial and it's all blank.

vinyl-junkie
02-25-2007, 03:40 PM
Did you download code from the tutorial? How about posting a link to the tutorial you're using?

JohnDubya
02-25-2007, 06:25 PM
I am using a tutorial and it's all blank.

Hello there! It's always good to post as much information as is possible for each situation. If there is code that has a problem, post it. If you're using a tutorial, post it. If there's a page we can look at that isn't showing up correctly, post it and the code it uses...etc. etc. Be as descriptive as possible! Good luck!

westmatrix99
02-25-2007, 08:53 PM
The tutorial is on this site:

http://codewalkers.com/tutorials/95/1.html

rafiki
02-26-2007, 12:01 PM
<?php
//Start the session so we can store what the code actually is.
session_start();

//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());

/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);


/*
Now for the GD stuff, for ease of use lets create
the image from a background image.
*/

$captcha = imagecreatefrompng("./captcha.png");

/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/

$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);

/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
/*
Now for the all important writing of the randomly generated string to the image.
*/
imagestring($captcha, 5, 20, 10, $string, $black);


/*
Encrypt and store the key inside of a session
*/

$_SESSION['key'] = md5($string);

/*
Output the image
*/
header("Content-type: image/png");
imagepng($captcha);
?>


thats the code he is using, to save you all from multipages of code i compiled into easy view :D

westmatrix99
02-26-2007, 01:14 PM
Cool thanks, will try to figure it out.

Cheers

westmatrix99
02-26-2007, 01:28 PM
When I run it I get this error:


Fatal error: Call to undefined function imagecreatefrompng() in c:\Inetpub\wwwroot\usermail\untitled.php on line 19

This on line 19:


$captcha = imagecreatefrompng("./captcha.png");
Any idea?

vinyl-junkie
02-26-2007, 04:02 PM
Have you read what the manual says about imagecreatefrompng (http://us3.php.net/imagecreatefrompng)? There are a couple of warnings about things which could cause this command to fail.

The easiest way to find out the settings on your server is to create a file with the following:


<?php
phpinfo();
?>
Upload that file to your server, run it, and check what the settings are for allow_url_fopen. That should be set to On.

westmatrix99
02-26-2007, 04:18 PM
Yes it's on

westmatrix99
02-26-2007, 04:20 PM
I ran this to test it

<?php
if (!function_exists('imagecreatefromjpeg')) {
echo 'imagecreatefromjpeg() exists.';
}
?>
and it returns this:


imagecreatefromjpeg() exists.

JohnDubya
02-26-2007, 04:36 PM
Your logic is looking to see if the function "imagecreatefromjpeg" does NOT exist (evident from the ! which means "NOT"), but your text is printing "exists." Do it like this:


<?php
if (function_exists('imagecreatefromjpeg')) {
echo 'imagecreatefromjpeg() exists.';
} else {
echo 'imagecreatefromjpeg() does not exist.';
}
?>

westmatrix99
02-26-2007, 04:37 PM
I tried for all and got a good response but still get an error:



<?php
if (!function_exists('imagecreatefromjpeg')) {
echo 'imagecreatefromjpeg() exists.<br>';
}
if (!function_exists('imagecreatefromgif')) {
echo 'imagecreatefromgif() exists.<br>';
}
if (!function_exists('imagecreatefrompng')) {
echo 'imagecreatefrompng() exists.<br>';
}
?>

Fumigator
02-26-2007, 04:37 PM
You don't have the GD library installed. You are confused as to what you are checking on those "if" statements-- you are saying if (NOT function_exists()) echo 'function exists!', so the fact they are all returning 'function exists' means they don't exist.

westmatrix99
02-26-2007, 04:39 PM
I think I have downloaded it but it says that it can't load it.

I have tried 2 versions:
PHP Version 4.x.x
and
PHP Version 5.1.4

PHP Warning: PHP Startup: Unable to load dynamic library './php_gd2.dll' - The specified module could not be found. in Unknown on line 0

Fumigator
02-26-2007, 04:42 PM
Better luck next time...

westmatrix99
02-26-2007, 04:45 PM
If I double click on php-cgi.exe in C:\PHP directory I get this error:


PHP Warning: PHP Startup: gd: Unable to initialize module
Module compiled with module API=20060613, debug=0, thread-safety=1
PHP compiled with module API=20050922, debug=0, thread-safety=1
These options need to match
in Unknown on line 0

westmatrix99
02-26-2007, 04:49 PM
I don't understand:

OK so what do I need to do?

vinyl-junkie
02-26-2007, 04:55 PM
Did you read the GD FAQ page (http://www.boutell.com/gd/faq.html)? That might have something that would help?

westmatrix99
02-26-2007, 06:56 PM
Got it working but you may need two things:
captcha.png attached
php_gd2.dll not attached sorry can't attach dll's or big zip files.


<?php
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());
/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);
/*
Now for the GD stuff, for ease of use lets create
the image from a background image.
*/
$captcha = imagecreatefrompng("./captcha.png");
/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
/*
Now for the all important writing of the randomly generated string to the image.
*/
imagestring($captcha, 5, 20, 10, $string, $black);
/*
Encrypt and store the key inside of a session
*/
$_SESSION['key'] = md5($string);
/*
Output the image
*/
header("Content-type: image/png");
imagepng($captcha);
?>

Thanks so much for your help guys and gals.
Cheers

westmatrix99
02-26-2007, 06:58 PM
How do I reslove this thread?

Thanks again.

vinyl-junkie
02-26-2007, 07:13 PM
How do I reslove this thread?

Thanks again.
Nothing else to do, since you got your code working. Congratulations! :thumbsup:

westmatrix99
02-26-2007, 08:36 PM
Dowload the file here:

:)
http://www.nabble.com/file/4867/php_gd2.dll
:)
Cheers
Thanks AGAIN!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum