【发布时间】:2011-08-24 16:28:11
【问题描述】:
我有一些代码来记录尝试了多少密码尝试,如下所示:
<?php
/* Access denied */
$_SESSION['error'] = "invalidlogin";
if (isset($_SESSION['tries']))
{
if ($_SESSION['tries'] == 5)
{
//TODO: Redirect somewhere nicer and more descriptive
header("location:/index.php");
}
else
{
$_SESSION['tries']++;
}
}
else
{
$_SESSION['tries'] = 0;
}
header("location:/login.php");
?>
我知道它最多数到五然后停止因为我通过在 login.php 上回显 $_SESSION['error'] 来测试它
PHP 在命中时从不重定向
header("location:/index.php");
但它总是继续前进,然后重定向到
header("location:/login.php");
如何让 PHP 在遇到 index.php 重定向后立即重定向?
我只是在 index.php 重定向后设置一个布尔值并在 login.php 重定向上检查它吗?
编辑:为了澄清,我已经定义了一个 session_start();别担心。
【问题讨论】:
标签: php redirect http-headers