As planned, the following login form should display an error message if the captcha was entered incorrectly:
<form name="from" method="post" action="signin.php"> ... <img src="captcha.php" alt="" /> <input type="text" name="captcha"> <?php if(isset($_SESSION['error_auth'])){echo $_SESSION['error_auth'];} ?> <input type="submit" value="Вход" disabled> </form> Checking the captcha in signin.php is as follows:
session_start(); if ($_SESSION['generatedCaptcha'] != $inputedCaptcha) { $_SESSION['error_auth'] = 'Введённые цифры не соответствуют сгенерированным'; // ... или просто не были введены header('Location: http://example.com/singin'); exit; } Using the debugger, I found that if the captcha was not entered, then we get into the above condition and the $_SESSION['error_auth'] variable is successfully initialized. Then, as you can see, it returns to the login page, where, according to the idea, the isset($_SESSION['error_auth']) condition must be met isset($_SESSION['error_auth']) .
However, for some reason, the $_SESSION['error_auth'] message is not displayed. What is the reason? In theory, these sessions should not be lost when returning to the login page after stopping the script.