Numaric Captcha

<?php

session_start();

function generate_equation() {
$firstnum = rand(5,8);
$secondnum = rand(1,4);
$coinflip = rand(1,2) % 2;
if($coinflip == 0) {
$math = $firstnum + $secondnum;
$operator = array("+");
} else {
$math = $firstnum - $secondnum;
$operator = array("-");
}

$_SESSION['captcha_equation'] = $firstnum . " " . $operator[0] . " " . $secondnum . " = ";
$_SESSION['captcha_answer'] = $math;

return( $_SESSION['captcha_equation'] );
}

?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s