ログインフォーム

<?php
header("Content-type: text/html; charset=utf-8");

define("ID", "vagrant");
define("PASSWORD", "asdf");

$post_id = @$_POST&#91;"id"&#93;;
$post_password = @$_POST&#91;"password"&#93;;
$val1 = @$_POST&#91;"val1"&#93;;
$val2 = @$_POST&#91;"val2"&#93;;
$val3 = @$_POST&#91;"val3"&#93;;

$mass = $val1 + $val2;

if($post_id == ID && $post_password == PASSWORD && $mass == $val3){
	echo "<p>ログイン成功</p>";
} elseif(!@$_POST){
	login_form();
} else {
	if($mass == $val3){
		echo "<p>ログイン失敗 IDまたはPASSWORDが間違っています。</p>";
	} else {
		echo "<p>ログイン失敗 計算の答えが間違っています。</p>";
	}
	login_form();
}

function login_form(){

	$rand1 = rand(0,9);
	$rand2 = rand(0,9);

	echo <<<LOGINFORM
	<!DOCTYPE html>
	<html lang="ja">
	<body>
	<form action="" method="post" id="login">
		<input type="text" name="id" placeholder="id">
		<input type="password" name="password" placeholder="password">
		<input type="text" name="val1" style="display:none;" value="{$rand1}">
		<input type="text" name="val2" style="display:none;" value="{$rand2}">
		<input type="text" name="val3" placeholder="{$rand1}+{$rand2}=の答えを入力">
		<input type="submit" value="ログイン">
	</form>
	</body>
	</html>
LOGINFORM;
}
?>