Lost Password?

  #1 (permalink)  
Old 04-29-2008, 08:20 AM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Moderator">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 817
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Creation of captcha / Part II /Secure forms

Okay here's our code of this captcha image:

PHP Code:
<?php
header
('Content-type: image/jpg');
$im imagecreatefromjpeg ("image.jpg");
$rand1 rand(1,255);
$rand2 rand(1,255);
$rand3 rand(1,255);
$color imagecolorallocate($im$rand1$rand2$rand3);
$text rand(10009999);
$font 'text-font.otf';
$size 30;
imagettftext($im$size07045$color$font$text);
imagejpeg($im);
imagedestroy($im);
?>
But if we want to use this image on our sites we must add:

PHP Code:
$_SESSION['captcha'] = $text
on the bottom of our captcha file. So.. now let's make our form secure.

First of all we must start the session

PHP Code:
<?php
session_start
();
session_start(); - Starts the session

Now I'm using a form for checking that is the security code correct

PHP Code:
if(isset($_POST['submit'])){
$ses $_SESSION['captcha'];
if(
$ses == $_POST['code']){
echo 
"Code is correct!";
}else{
echo 
"Code is incorrect!";

if(isset($_POST['submit']) && !empty($_POST['code'])){ - If someone has clicked the submit button let's continue with our script
$ses = $_SESSION['captcha']; - Let's get the captcha code from the session
if($ses == $_POST['code']){ - If captcha's code is same as the code you posted
echo "Code is correct!"; - let's say that the code was correct
}else{ - but if they are not same
echo "Code is incorrect!"; - let's say that the code is not correct
} - This ends the if and else statement

PHP Code:
}else{
echo 
"<img src='captcha.php'><br>";
echo 
"<form action='' method='post'>"
    
."<input type='text' name='code'>"
    
."<input type='submit' name='submit' value='Enter'>"
    
."</form>";

}else{ - If anyone hasnt clicked the submit button let's display our form
echo "<img src='captcha.php'><br>"; - Shows our captcha image
echo "<form action='' method='post'>"
."<input type='text' name='code'>"
."<input type='submit' name='submit' value='Enter'>"
."</form>";
- Our form
} - This ends the if and else statement



And we are done.. that was so simple
You can customize this script for your forms

Here's the full script:

captcha.php
PHP Code:
<?php
session_start
();
$im imagecreatefromjpeg ("image.jpg");
$rand1 rand(1,255);
$rand2 rand(1,255);
$rand3 rand(1,255);
$color imagecolorallocate($im$rand1$rand2$rand3);
$text rand(10009999);
$font 'text-font.otf';
$size 30;
imagettftext($im$size07045$color$font$text);
header('Content-type: image/jpg');
imagejpeg($im);
imagedestroy($im);
$_SESSION['captcha'] = $text;
?>
index.php
PHP Code:
<?php
session_start
();

if(isset(
$_POST['submit']) && !empty($_POST['code'])){
$ses $_SESSION['captcha'];
if(
$ses == $_POST['code']){
echo 
"Code is correct!";
}else{
echo 
"Code is incorrect!";
}
}else{
echo 
"<img src='captcha.php'><br>";
echo 
"<form action='' method='post'>"
    
."<input type='text' name='code'>"
    
."<input type='submit' name='submit' value='Enter'>"
    
."</form>";
}
?>
I attached the files also
Enjoy!
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
__________________


Cheap & Professional Web Design | Need help? Send a PM

Last edited by Jordan; 05-07-2008 at 12:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-02-2008, 11:43 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,518
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Creation of captcha / Part II /Secure forms

Thanks, Jaan! There are various premade scripts available, but creating your own is easier to integrate.
I think the other type of captchas are better, where it is just plain black text with a warped line through it. It does not require a background, and so fits in to web pages more smoothly. Nice tutorial, though.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-02-2008, 03:15 PM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Moderator">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 817
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Creation of captcha / Part II /Secure forms

thanks
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-02-2008, 09:45 PM
John's Avatar   
John John is online now
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,784
Last Blog:
Passwords
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default Re: Creation of captcha / Part II /Secure forms

Quote:
Originally Posted by Xav View Post
Thanks, Jaan! There are various premade scripts available, but creating your own is easier to integrate.
I think the other type of captchas are better, where it is just plain black text with a warped line through it. It does not require a background, and so fits in to web pages more smoothly. Nice tutorial, though.
Those types of captchas are useless. I've considered writing a tutorial on how to bypass captchas like that...
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-03-2008, 07:39 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,518
Last Blog:
Web slideshow in JavaS...
Rep Power: 46
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Creation of captcha / Part II /Secure forms

Really? I thought it was difficult to distinguish the letters when there was a line through them? How about the fuzzy-letters one?
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 05-22-2008, 09:04 AM
Metanet Metanet is offline
Newbie
 
Join Date: May 2008
Posts: 1
Rep Power: 0
Metanet is on a distinguished road
Default Re: Creation of captcha / Part II /Secure forms

Thanks for the tutorial
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-22-2008, 12:08 PM
knaleffect knaleffect is offline
Newbie
 
Join Date: May 2008
Posts: 2
Rep Power: 0
knaleffect is on a distinguished road
Default Re: Creation of captcha / Part II /Secure forms

Thank for the tutorial
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-23-2008, 10:20 AM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Moderator">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 817
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Creation of captcha / Part II /Secure forms

you're welcome
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-25-2008, 03:05 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 7,360
Rep Power: 67
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: Creation of captcha / Part II /Secure forms

What about the captcha that rapidshare.com has? It has a captcha with 6 digits, but 4 of them have a cat behind them, and you have to write the ones with the cat... does that work the same way?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-25-2008, 07:23 AM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Moderator">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 817
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Creation of captcha / Part II /Secure forms

hmmm..this rapidshare thingy is really lame..
that's why i bought a premium account..
uumm.. i believe rapidshare uses a little trick there..
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creation of captcha Jaan PHP Tutorials 7 08-21-2008 02:12 PM


All times are GMT -5. The time now is 05:44 PM.