<?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'] ); } ?>