【发布时间】:2013-03-01 16:59:13
【问题描述】:
我有下面的代码,它允许会员恢复他们的密码。但是我无法发现所犯的错误并且我的条件没有得到满足。当您访问recover.php 时,您将被重定向到index.php,因此最后一个else 语句正在执行(这应该只在用户登录时发生——这意味着如果他们已登录,他们将无法恢复密码)。
<?php
include 'storescripts/init.php';
$msg = "";
if(isset($_GET['success']) === true && empty($_GET['success']) === true)
{
$msg = "Thanks, we've emailed you.";
}
else
{
$mode_allowed = array('mem_password');
if (isset($_GET['mode']) === true && in_array($_GET['mode'], $mode_allowed) === true)
{
if(isset($_POST['mem_email']) === true && empty($_POST['mem_email']) === false)
{
if (email_exists($_POST['mem_email']) === true)
{
recover($_GET['mode'], $_POST['mem_email']);
header('Location: recover.php?success');
exit();
}
else
{
$msg = "<p>Oops, we couldn\'t find that email in the system</p>";
}
}
}
else
{
header('Location: index.php');
exit();
}
}
logged_in_redirect();
include 'includes/overall/head.php';
include 'includes/overall/template_header.php';
?>
<div id="mainDivShort">
<h1>Recover</h1>
<div id="divBreak"></div>
<?php include ("includes/overall/column_left.php");?>
<div id="middleContent">
<?php echo $msg; ?>
<form action="" method="post">
<ul>
<li>Please enter your email address:<br> <input type="text" name="mem_email"></li>
<li><input type="submit" value="Recover"></li>
</ul>
</form>
</div>
<?php include ("includes/overall/column_right.php");?>
</div>
<?php include ("includes/overall/template_footer.php");?>
当我退出时访问recover.php,我无法确定执行最后一个else语句的条件错误。
【问题讨论】:
-
$_GET['mode']在 URL 中传递?recover.php?mode=mem_password -
这不是您的错误,但您不需要在
true上进行显式比较。只需使用类似if (isset($foo) && !empty($foo)) -
不。我从 index.php 链接到 recover.php?mode=password ,一旦单击链接,我就会被重定向回 index.php