【发布时间】:2013-01-15 17:21:07
【问题描述】:
我很难找出我的 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?成功
【问题讨论】:
-
empty($_GET['success']) == true 抱歉,为什么要添加额外的代码,而不能只检查 empty($_GET['success']) ?并且 isset 本身返回 true 或 false 无需使用 == true 进行检查
-
您可能应该使用 POST,即使您重定向也是在使用 GET 共享个人信息。
-
已发送 HTML 后无法发送标头。你必须先做标题。此外,您应该编写一个 5 秒的重定向,而不是立即重定向,以便用户可以阅读您的消息,告诉他们他们已激活。
<head><meta http-equiv="refresh" content="5; url=index.php"></head> -
如果我理解正确并且上面的代码在
empty($_GET['success'] == true)中包含在activate.php中,那么如果它有效,你会得到一个无限的标头重定向错误。你的逻辑需要重新审视。
标签: php