SunQuest
 
       Miscellaneous
  Home arrow Miscellaneous arrow Page 3 - Creating a CAPTCHA with PHP
Moblin
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Creating a CAPTCHA with PHP
By: Andrew Walsh
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 43
    2006-06-06

    Table of Contents:
  • Creating a CAPTCHA with PHP
  • How does a CAPTCHA work?
  • Creating the random text
  • Writing the text to the image
  • Check if the user entered the code correctly
  • Improvements and Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Try It Free
     
    ADVERTISEMENT

    Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!

    Creating a CAPTCHA with PHP - Creating the random text


    (Page 3 of 6 )

    Right now we are up to generating the random text. To do this I will use the php functions, microtime() and mktime() to generate a number. This number will then be encrypted using md5(). With this 32 character long encrypted string we will then use substr() to cut it down to a 5 letter long string. This is our random text.

    Note: You may notice session_start() at the top of this script, this is to start the session which will be used later....

    <?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);
    ?>

    Next we will write this string to the image and output it to the user

    More Miscellaneous Articles
    More By Andrew Walsh


       · The Text: As you can see from the code above we are loading the basic image from...
       · Ok it will be corrected soon
       · My bad...I fixed this yesterday...
       · I have been meaning to get a Captcha image installed on my little application. As...
       · Can i use this code to play around and use it in a wordpress (http://wordpress.org)...
       · Problem to use in Post nukewhen i impliment the captcha on post nuke web then i...
       · You can do what you like with it, although i thought wordpress included a much...
       · By changing this line:$string = substr($md5,0,5);With the following gives you...
       · By changing this line:$string = substr($md5,0,5);With the following gives you...
       · I get a problem that dont show the picture it shows alot of strange text...
       · &lt;?php//Start the session so we can store what the code actually...
       · This was the base of the new captcha I made, except I did things a little...
       · please add this to the headers partheader(&quot;Cache-Control: no-cache,...
       · All goes well on a new page but I get this message when I incorporate it in an...
       · I get the same error when I don't start the session above the <html> tags,...
       · The site http://www.trycaptcha.com lets you try a bunch of open source CAPTCHA...
       · This tutorial really helped me out, thanks for the source!
       · Thanks for helpful little tutorial on how to do CAPTCHA! Never had to think about it...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway