我很难弄清楚PHP用户/注册网站的错误。 注册后,会发送带有激活链接的电子邮件,当单击该链接时,它会成功激活该帐户,但不会显示成功消息。
如果我在浏览器中复制/粘贴激活链接并更改链接中的电子邮件或电子邮件代码中的字母,它将成功地向我提供所有错误消息。
激活链接如下所示:
这是我的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'; ?>
为什么它不会给我成功消息和重定向?
于: website.com/activate.php?success
答案 0 :(得分:0)
这条线有些可疑:
if (isset($_GET['success']) == true && empty($_GET['success']) == true) {
你确定它不是&& empty($_GET['success']) == false)
吗?
答案 1 :(得分:0)
从不使用 HTML代码命令使用 HTMLcode&lt;?php PHPcode 语法。
基本上:您首先输出一个字符串(您的HTML代码),然后尝试输出标题
这是不正确的。标题需要在发送之前发送。你想要做的是将整个文档转换为PHP(文档的第一个字符应该是&lt;?php ),然后使用heredoc语法实际插入一段HTML代码,并且回显它们(所有收集到一个变量并在代码的最后一行回显)。避免将PHP与HTML混合,就像您在此处不惜一切代价一样。
答案 2 :(得分:0)
您将其设置为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();
}
答案 3 :(得分:0)
您应该测试哪些条件失败,请参阅下文。作为旁注:如果你没有通过状态,你不需要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
测试上述代码时,它会重定向我。
修改强>
如果我理解正确并且您在empty($_GET['success'] == true)
内使用activate.php
上面的代码,那么如果它有效,您将收到无限的标头重定向错误。您的逻辑需要重新审视。