繁体   English   中英

成功消息未显示,并且URL未重定向到activate.php?成功

[英]Success message is not showing and url is not redirected to activate.php?success

我很难找出我的PHP用户/注册站点的错误。 注册后,会发送一封带有激活链接的电子邮件,单击该链接会成功激活该帐户,但不会显示成功消息。

如果我在浏览器中复制/粘贴激活链接并更改链接中的电子邮件或电子邮件代码中的字母,它将成功给我所有错误消息。

激活链接如下所示:

http://website.com/activate.php?email=useremail@website.com&email_code=2631df446b129480abdbf54f08e8c494

这是我的activate.php的代码

<?php 
include 'core/init.php';
logged_in_redirect();
include 'includes/overall/header.php';
?>

<?php 
if (isset($_GET['success']) == true && empty($_GET['success']) == true) {
    ?>
<h3>Thanks, your account has been activated..</h3>
<p>You're free to log in!</p>
<?php
    header('Location: activate.php?success');
    exit();
} else if (isset($_GET['email'], $_GET['email_code']) === true) {

$email      = trim($_GET['email']);
$email_code = trim($_GET['email_code']);

if (email_exists($email) === false) {
    $errors[] = 'Ooops something went wrong, and we couldn\'t find that email adress!';
    } else if (activate($email, $email_code) === false) {
    $errors[] = 'We had problems activating your account';
    } if (empty($errors) === false) {
?>
    <h2>Ooops...</h2>
<?php
    echo output_errors($errors);
} else {
    header('Location: activate.php?success');
    exit();
}
} else {
header('Location: index.php');
exit();
}
?>

<?php include 'includes/overall/footer.php'; ?>

为什么不给我成功消息并重定向?

该URL不会从以下位置更改: http : //website.com/activate.php?email=useremail@website.com&email_code=2631df446b129480abdbf54f08e8c494

到:website.com/activate.php?成功

关于这条线有一些可疑之处:

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

您确定不是&& empty($_GET['success']) == false)吗?

绝对不要将HTMLcode <?php PHPcode语法与标头命令一起使用。
基本上:您首先输出一个字符串(您的HTML代码),然后尝试输出标头。
那是不对的 头需要什么之前发送。 您要做的是将整个文档转换为PHP(文档的第一个字符应为<?php ),然后使用Heredoc语法实际插入一段HTML代码,并将其回显(将所有内容收集到一个变量中,并在代码的最后一行)。 避免不惜一切代价将PHP与HTML混合使用。

您将其设置为if activate == true并清空重定向到该确切页面,以便获得重定向循环。

if (isset($_GET['success']) == true && empty($_GET['success']) == true) {
        header('Location: activate.php?success');
        exit();
}

尝试

if (isset($_GET['success']) == true && empty($_GET['success']) == true) {
       echo "It worked";
       exit();
}

您应该测试哪个条件失败,请参见下文。 作为一个方面说明:您不需要在括号exit ,如果你不传递的状态经过,你也不需要打开和关闭PHP这么多,这是没有必要的:

<?php 
include 'core/init.php';
logged_in_redirect();
include 'includes/overall/header.php';

if (isset($_GET['success']) && !empty($_GET['success'])) {
    //in activate.php isset($_GET['success']) add this ouput, 
    //it works / not recommended and never seen.
    //echo "<h3>Thanks, your account has been activated..</h3>";
    //echo "<p>You're free to log in!</p>";
    header('Location: activate.php?success');
    exit;
} else if (isset($_GET['email'], $_GET['email_code'])) {
    $email = trim($_GET['email']);
    $email_code = trim($_GET['email_code']);
    if (email_exists($email) === false) {
        $errors[] = 'Ooops something went wrong, and we couldn\'t find that email adress!';
    } else if (activate($email, $email_code) === false) {
        $errors[] = 'We had problems activating your account';
    } if (empty($errors) === false) {
        echo "<h2>Ooops...</h2>";
        echo output_errors($errors);
    } else {
        header('Location: activate.php?success');
        exit;
    }
} else {
    // The following 2 lines: You should see 1, 0 or nothing
    // From there you should be able to troubleshoot.        
    echo "isset: ".isset($_GET['success'])."<br>";
    echo "Empty: ".empty($_GET['success']);
    //header('Location: index.php');
    exit;
}
include 'includes/overall/footer.php';

当我用?success测试上面的代码时,它对我来说重定向正确。

编辑:

如果我正确理解并且上面的代码在activate.php包含empty($_GET['success'] == true) ,那么如果它起作用,您将收到一个无限的标头重定向错误。 您的逻辑需要重新审视。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM