2011-01-20 100 views
1

我正在寻找一种方法来通知有登录凭据失败,这样用户:PHP isset失败的用户登录

因此,在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; 
    } 

目前,重定向的工作,他们没有得到登录,但通知的心不是让呼应?

+0

在浏览器重定向 – 2011-01-20 11:19:12

回答

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>"; 
} 
?> 
+0

之后,您正在回应消息!谢谢 – benhowdle89 2011-01-20 11:21:51

0

从你给的代码,似乎你从来没有设置$fail