1

我正在寻找一种方法来通知用户登录凭据失败,如下所示:

所以在 index.php 的顶部(他们登录并在登录失败时被重定向到)我有:

 <?php 
 if (isset($fail)) {
  echo "<p>Failed Login</p>";
 } 
 ?>

对凭据的检查是这样的:

  if($ensure_credentials) {
   $_SESSION['status'] = 'authorized';
   $_SESSION['username'] = $un;
   header("location: ../".$un.".php");
  } else {
   header("location: ../index.php");
   echo $fail;
  }

目前,重定向正在工作,他们没有登录,但通知没有得到回应?

4

2 回答 2

2

一个简单的解决方案是在登录失败后重定向到 index.php 页面时添加一个查询字符串参数:

if($ensure_credentials) {
   $_SESSION['status'] = 'authorized';
   $_SESSION['username'] = $un;
   header("location: ../".$un.".php");
  } else {
   header("location: ../index.php?fail=1");
  }

在 index.php 的顶部添加:

 <?php 
 if (isset($_GET['fail']) && ($_GET['fail'] == '1'))) {
     echo "<p>Failed Login</p>";
 } 
 ?>
于 2011-01-20T11:18:13.447 回答
0

从您提供的代码来看,您似乎从未设置$fail.

于 2011-01-20T11:18:56.003 回答