【发布时间】:2013-02-03 08:31:01
【问题描述】:
我一直在尝试、搜索、尝试、研究一整夜,以了解如何在 PHP 登录成功后让页面淡出,然后在成功淡出后重定向到受保护的页面。
这是我目前所拥有的,尽管它是我一直在尝试的众多更改中的最新一项:
链接: ournewlife.com/002/login.php
和代码:
<?php
session_start();
if ($_GET['login']) {
// Only load the code below if the GET
// variable 'login' is set. You will
// set this when you submit the form
if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
// Load code below if both username
// and password submitted are correct
$_SESSION['loggedin'] = 1;
// Set session variable
echo "<script type='text/javascript'>";
echo "$('#ournewform').fadeOut(2222);";
echo "</script>";
// header("Location: protected.php");
exit;
// Redirect to a protected page
} else echo "";
// Otherwise, echo the error message
}
?>
<form action="?login=1" method="post" id="ournewform">
<input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
我还尝试在从单独的 .js 文件中按下回车键后加载转换,但是 PHP 不会更新会话,并且当它重定向时,登录尚未得到验证,并且会将我吐回登录页面。
这里有什么我遗漏的吗?我只是想在有效登录后淡出页面,然后成功进入受保护页面。
我现在注释掉了重定向行,以便我可以在 jQuery 上工作。
【问题讨论】:
-
回显出来的js代码永远不会被执行;这是因为您正在回显脚本数据,然后尝试重定向。此外,它会给出一个名为“警告:无法修改标头信息 - 标头已发送”的警告