Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2007, 02:43 PM   PM User | #1
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
Question Captcha

How to create a captcha, have tried lines of captcha code but images are always blank.
So how do I do this?
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-25-2007, 03:18 PM   PM User | #2
vinyl-junkie
$object->toCD-R(LP);


 
vinyl-junkie's Avatar
 
Join Date: Jun 2003
Posts: 3,053
Thanks: 2
Thanked 22 Times in 22 Posts
vinyl-junkie is on a distinguished road
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.
__________________
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
SNAP to it!
vinyl-junkie is offline   Reply With Quote
Old 02-25-2007, 03:26 PM   PM User | #3
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
I am using a tutorial and it's all blank.
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-25-2007, 03:40 PM   PM User | #4
vinyl-junkie
$object->toCD-R(LP);


 
vinyl-junkie's Avatar
 
Join Date: Jun 2003
Posts: 3,053
Thanks: 2
Thanked 22 Times in 22 Posts
vinyl-junkie is on a distinguished road
Did you download code from the tutorial? How about posting a link to the tutorial you're using?
__________________
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
SNAP to it!
vinyl-junkie is offline   Reply With Quote
Old 02-25-2007, 06:25 PM   PM User | #5
JohnDubya
Super Moderator


 
JohnDubya's Avatar
 
Join Date: Nov 2006
Location: Missouri
Posts: 633
Thanks: 12
Thanked 18 Times in 18 Posts
JohnDubya is on a distinguished road
Quote:
Originally Posted by westmatrix99 View Post
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!
__________________
JDub
http://johnnyzone.com/blog
JohnDubya is offline   Reply With Quote
Old 02-25-2007, 08:53 PM   PM User | #6
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
The tutorial is on this site:

http://codewalkers.com/tutorials/95/1.html
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-26-2007, 12:01 PM   PM User | #7
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
PHP Code:
<?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($captcha000);
$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($captcha52010$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
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 02-26-2007, 01:14 PM   PM User | #8
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
Cool thanks, will try to figure it out.

Cheers
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-26-2007, 01:28 PM   PM User | #9
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
When I run it I get this error:

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

Quote:
$captcha = imagecreatefrompng("./captcha.png");
Any idea?
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-26-2007, 04:02 PM   PM User | #10
vinyl-junkie
$object->toCD-R(LP);


 
vinyl-junkie's Avatar
 
Join Date: Jun 2003
Posts: 3,053
Thanks: 2
Thanked 22 Times in 22 Posts
vinyl-junkie is on a distinguished road
Have you read what the manual says about 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:

Code:
<?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.
__________________
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
SNAP to it!
vinyl-junkie is offline   Reply With Quote
Old 02-26-2007, 04:18 PM   PM User | #11
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
Yes it's on
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-26-2007, 04:20 PM   PM User | #12
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
I ran this to test it
Code:
<?php
if (!function_exists('imagecreatefromjpeg')) { 
     echo 'imagecreatefromjpeg() exists.'; 
}  
?>
and it returns this:

Quote:
imagecreatefromjpeg() exists.
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-26-2007, 04:36 PM   PM User | #13
JohnDubya
Super Moderator


 
JohnDubya's Avatar
 
Join Date: Nov 2006
Location: Missouri
Posts: 633
Thanks: 12
Thanked 18 Times in 18 Posts
JohnDubya is on a distinguished road
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 Code:
<?php
if (function_exists('imagecreatefromjpeg')) { 
     echo 
'imagecreatefromjpeg() exists.'
} else {
     echo 
'imagecreatefromjpeg() does not exist.';
}
?>
__________________
JDub
http://johnnyzone.com/blog
JohnDubya is offline   Reply With Quote
Old 02-26-2007, 04:37 PM   PM User | #14
westmatrix99
Regular Coder

 
westmatrix99's Avatar
 
Join Date: Dec 2006
Location: South Africa
Posts: 307
Thanks: 12
Thanked 0 Times in 0 Posts
westmatrix99 is an unknown quantity at this point
I tried for all and got a good response but still get an error:


Quote:
<?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>';
}
?>
__________________
Thanks for you support!
westmatrix99 is offline   Reply With Quote
Old 02-26-2007, 04:37 PM   PM User | #15
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:19 PM.


Advertisement
Log in to turn off these ads.