<?php
session_start();
$op_arr = ['+','-','*'];
$no1 = rand(10,20);
$op = $op_arr[rand(0,2)];
$no2 = rand(1,9);
$sum = "{$no1}"."{$op}"."{$no2}";
$result = eval("return $sum;");
$captcha = $sum;
$_SESSION['result']= $result;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text captch example</title>
</head>
<body>
<h1><center>TEXT CAPTCHA</center></h1>
<hr>
<form action="mathcode.php" method="post">
<p>Enter the email : <input type="text" name="email"/></p>
<p>Solve the expression : <strike><mark><?php echo $captcha; ?> =</mark></strike> <br>
<input type="text" name="captcha" /></p>
<p><input type="submit" name="submit"/></p>
</form>
</body>
</html>
============mathcode.php===========
<?php
$email = $_POST['email'];
$captcha = $_POST['captcha'];
session_start();
$sess_capcha = $_SESSION['result'];
echo $sess_capcha;
?>
0 Comments