Text captch example


<?php

// $c1 = rand(0,9);

// $c2 = rand(0,9);

// $c3 = rand(0,9);

// $c4 = rand(0,9);

// $c5 = rand(0,9);

//$captcha = $c1.$c2.$c3.$c4.$c5;

session_start();

$c_arr = [];

$size = 6;

for ($i=0; $i<$size; $i++) {

$c_arr[$i] = rand(0,9);

}

$captcha = join($c_arr);

$_SESSION['captcha']= $captcha;

?>

<!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="testcode.php" method="post">

<p>Enter the email : <input type="text" name="email"/></p>

<p>Enter the Captcha : <strike><mark><?php echo $captcha; ?></mark></strike> <br>

<input type="text" name="captcha"  /></p>

<p><input type="submit" name="submit"/></p>

</form>

</body>

</html>


========testcode.php============


<?php

$email = $_POST['email'];

$captcha = $_POST['captcha'];

session_start();

$sess_capcha = $_SESSION['captcha'];

echo $sess_capcha;

?>