JavaScript Editor Ajax software     Free javascripts 



Main Page

3.
In your
seophp/include
library, create a file named
simple_captcha.inc.php
, and then
type this code in:
<?php
// load Words library
require_once(‘Numbers/Words.php’);
// SimpleCAPTCHA library
class SimpleCAPTCHA
{
// verify answer
function check_answer($answer, $hash)
{
return (md5(trim($answer) . $_SERVER[‘SERVER_ADDR’]) == $hash);
}
// generate question
function get_question($max_1, $max_2)
{
// define standard question formats
$question_formats = array(
‘What is %s plus %s?’,
‘What is the sum of %s and %s?’,
‘What is %s added to %s?’,
‘What is %s + %s?’
);
// generate random numbers
$number_1 = rand(0, $max_1);
$number_2 = rand(0, $max_2);
// transforms the numbers to words
$number_1_words = Numbers_Words::toWords($number_1);
$number_2_words = Numbers_Words::toWords($number_2);
// generate a random question
$question = sprintf($question_formats[rand(0,
sizeof($question_formats) - 1)],
$number_1_words,
$number_2_words);
// returns the question and the hash of the result
return array(‘question’ => $question,
‘hash’ => md5(($number_1 + $number_2) . $_SERVER[‘SERVER_ADDR’]));
}
// generates demo form
function display_demo_form()
{
$gq = SimpleCAPTCHA::get_question(1000, 10);
echo ‘<form>’;
echo $gq[‘question’];
190
Chapter 8: Black Hat SEO
c08.qxd:c08 10:59 190


JavaScript Editor Ajax software     Free javascripts