我的IF声明中没有达到的条件

时间:2013-03-01 16:59:13

标签: php html

我有以下代码,允许会员恢复他们的密码。但是我无法发现所犯的错误并且我的条件没有得到满足。当你访问recover.php时,你被重定向到index.php,所以最后一个else语句正在执行(这应该只在用户登录时发生 - 这意味着如果他们登录就无法恢复密码。) / p>

<?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语句的条件是什么。

1 个答案:

答案 0 :(得分:0)

首先:

这不起作用:

if(isset($_GET['success']) === true && empty($_GET['success']) === true)

应该是:

if(isset($_GET['success']) === true && empty($_GET['success']) === false)

header('Location: recover.php?success');

应该是(否则不会设置$ _GET ['success']):

header('Location: recover.php?success=1');

<form action="" method="post">

应该是:

<form action="recover.php?mode=mem_password" method="post">

对于其余部分,您的代码是正确的。