Показване/Скриване на Captcha

bganonymous

Registered
Имам Login форма. Искам ако на потребителя му е дало съобщение за грешно име и/или парола, да показва Captcha-та. Как може да стане това? :)
 
Да предположим, че имаш примерна форма..

Това е за което се сетих.. не е много яко , но за прост код ще му схванеш идеята.

PHP:
<?php
if(isSet($_POST['submit'])) {
	$username = isSet($_POST['username']) ? $_POST['username'] : "";
	$password = isSet($_POST['password']) ? $_POST['password'] : "";
	if(isSet($_SESSION['error_captcha']) && ($_SESSION['error_captcha'] == 1)) {
		if($_POST['captcha'] != $_SESSION['error_captcha']) {
			echo "Грешка при captcha!";
			exit();
		}
	}
	if(empty($username) && empty($password)) {
		echo "field is empty";
	} else {
		if($username = "admin" && $password = "admin") {
			echo "OK";
			$_SESSION['error_captcha'] = 0;
		} else {
			$_SESSION['error_captcha'] = 1;
			echo "Error user/password details.";
		}
	}
}
?>
<form method="POST" action="">
<?php
if(isSet($_SESSION['error_captcha']) && ($_SESSION['error_captcha'] == 1)) {
	echo "<img src='captcha.php' alt='' /><input type='text' name='captcha' />";
}
?>
User: <input type="text" name="username" /><br />
Pass: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Test" />
</form>
 

Back
Горе