我有一个由echo显示的表单,我试图在提交后刷新页面,以便当输入无效详细信息时,可以将登录尝试添加到计数中,显示表单但是页面不会再刷新以添加算一算,这就是我所拥有的:
$pdo = new PDO($dsn, $username, $password, $options);
$max_time_in_seconds = 10;
$max_attempts = 3;
if(login_attempt_count($max_time_in_seconds, $pdo) <= $max_attempts) {
$form = "<form name='login' class='profile' id='form_id' action=''
method='post' accept-charset='utf-8'>
<fieldset>
<legend>Login</legend>
<label for='username'>User name</label>
<input type='text' name='username' id='username' autofocus
placeholder='User name MAX 10' maxlength='10' title='You can
use characters & numbers' required />
<label for='password'>Password</label>
<input type='password' id='password' name='password'
/>
<br>
<input type='submit' class='btn' value='Login' id='submit'
onSubmit='window.parent.location.reload();' />
</form>";
} else {
$msg2 = " You have been BLOCKED try again in 10 minutes";
}
如果我刷新页面三次被阻止,这就是我想要输入三次提交的内容 我试过添加
<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>
我只是空白的白屏......
if($_SESSION['user'] { header("location: memberlist.php"); }
else
if($_SESSION['user']['blacklisted_users'] == 'blocked') {
header("location: blocked.php");}
else
header("Location: private.php");
die("Redirecting to: private.php");
}
else
{
$msg = " Username or Password INCORRECT";
}
我认为最后的其他方法是阻止页面刷新,因为它只是回显错误
登录检查:
$query = "
SELECT
id,
username,
password,
salt,
email,
firstname,
surname,
address,
town,
postcode,
type,
blacklisted_users
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$login_ok = false;
$row = $stmt->fetch();
if($row)
{
然后进行密码检查......
答案 0 :(得分:0)
您忘记关闭Replace
标记了。在结束表单标记<fieldset>
之前添加</fieldset>
。
编辑:
你的中有些错误
您应该在</form>
之后添加exit();
此外,header();
只是一个变量,将其更改为$_SESSION['user']
,因为我认为这就是您要做的事情
你也错过了一些isset($_SESSION['user'])
{}