Miscellaneous

  Home arrow Miscellaneous arrow Page 3 - Creating a CAPTCHA with PHP
MISCELLANEOUS

Creating a CAPTCHA with PHP
By: Andrew Walsh
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 141
    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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    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

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap