I’m trying to implement a simple captcha into a form I’m building but I’ve run up against an issue I can’t seem to sort out by myself.
I’m using simple code to generate a random number like so ….
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
…. and then some more code to generate an image of the random number and display it on the page. I’m against it for validity like this ….
if (strlen($captcha) !== ($_SESSION['randomnr2'])) {
$error['captcha'] = "CAPTCHA error. Please try again";
}
How do I go about checking the value that’s been input into the captcha input field against the random number that’s stored in the session randomnr2?
I’m not sure why you are checking the length of the string against an md5 hash of the string here, but assuming
$captchais the number from the user, you can just do this: