<?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>