Blog Home Dudermang

PHP captcha

by Corey Faulkerson

Posted on 2018-01-14 08:37:57



<?php session_start(); if(isset($_REQUEST['email'])){ if(isset($_REQUEST['guess'])){ $guess = $_REQUEST['guess']; //echo $guess; if($guess == $_SESSION['answer']){ echo 'Correct answer.'; }else{ //wrong answer echo "Wrong Answer"; //redirect to try again header('location: index.php'); } }else{// guess was not supplied } }else{// email was not supplied $num1 = rand(1,10); $num2 = rand(1,10); $num3 = $num1 + $num2; $_SESSION['answer']= $num3; echo' <form> <p><input type="text" name="email" placeholder="email"/></p> <p>Solve the math problem.</p> <p><input type="text" name="guess" placeholder="'.$num1.' + '. $num2.' ='.'"/></p> <p><input type="submit" name="submit" /></p> '; } ?> Back

Keywords

php, captcha, form, spam, security