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
Next: Writing the text to the image >>
More Miscellaneous Articles
More By Andrew Walsh
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|