我很难在PHP用户/注册站点上找出一个错误。注册后,使用激活链接发送电子邮件,当单击该链接时,它将成功激活帐户,但它没有显示成功消息。
如果我在浏览器中复制/粘贴激活链接,并在链接中的电子邮件或电子邮件代码中更改一个字母,它将成功地给出所有错误消息。
激活链接如下所示:
http://website.com/activate.php?email=useremail@website.com&email
这是我的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'; ?>为什么它不给我成功的信息和重定向?
网址不更改:code=2631df446b129480abdbf54f08e8c494
到:website.com/activate.php?成功
发布于 2013-01-31 15:10:44
您应该测试哪些标准不合格,请参见下面。另外,请注意:如果不传递状态,则不需要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中的代码,那么如果它有效,您将得到一个无限的头重定向错误。你的逻辑需要重新审视。
https://stackoverflow.com/questions/14628639
复制相似问题