I am wending my way through chapter 1 of this book, and for the most part I am using code that was downloaded from the Wrox website, and I am still running into problems.
I couldn't get the random text generator to work properly, so I created one of my own. I found this function on the web, and it didn't work either until I played around with it a bit.
PHP Code:
<?php
// return a string of random text of a desired length
function random_text($count, $rm_similar = false) {
// create list of characters
$chars = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y",
"Z", "2", "3", "4", "5", "6", "7", "8", "9");
shuffle($chars);
// remove similar looking characters that might cause confusion
if ($rm_similar) {
unset($chars[0], $chars[1], $chars[2], $chars[5], $chars[8], $chars['B'], $chars['I'], $chars['O'], $chars['S'], $chars['U'],
$chars['V'], $chars['Z']);
}
// generate the string of random text
$text = '';
for ($i = 0; $i < $count; $i++) {
$num = mt_rand(0, count($chars) - 1);
$text .= $chars[$num];
}
return $text;
}
?>
If you wanted to you could also add lower case letters or special characters to the array to make the captcha even more complex.