成功登录时的JQueryMobile登录页面重定向

时间:2013-04-10 18:58:22

标签: php javascript jquery-mobile

成功登录后,尝试将用户重定向到index.php。我有一切工作,除了重定向。一直在寻找大约一个小时现在没有运气..我敢肯定它与拥有该页面的jQueryMobile有关

尝试了

header('Location: index.php');  
没有任何反应。

也试过

echo '<script type="text/javascript">$.mobile.changePage($(\'index.php\'), {transition : "slide"});</script>';

如果我将它们作为我的PHP代码的第一部分,它们都会重新指向,但是当它放在我需要它的地方时它们什么都不做。

这是我的代码:

<?php include "layouts/header.php"; 
if (isset($_POST['submit'])) { // Form has been submitted.

  $username = trim($_POST['username']);
  $password = trim($_POST['password']);

  // Check database to see if username/password exist.
    $hashpass = sha1($password);
    $found_user = User::authenticate($username, $hashpass);

  if ($found_user) {
    $session->login($found_user);
    $message = "Logged in";
    // Redirect to index.php ********

  } else {
    // username/password combo not found 
    $message = "Username/password combination incorrect.";
    $forgotdisplay = "visible";
  }

} else { // Form was not been submitted.
  $username = "";
  $password = "";
}
?>
</head>
<body>
 <div data-role="page" id="loginForm">
    <div data-role="header">
      <h1>Assessment</h1>
    </div>
    <div data-role="content" class="centerContent">
        <h2>Login</h2>
        <p><?php echo output_message($message); ?></p>
        <form action="login.php" method="post" data-ajax="false">
          <table>
            <input type="text" id="username" name="username" maxlength="50" placeholder="username" value="<?php echo htmlentities($username); ?>" />
            <input type="password" id="password" name="password" maxlength="30" placeholder="password" value="<?php echo htmlentities($password); ?>" />            
            <input type="submit" name="submit" value="Login" />       
        </form>
        <a href="register.php" data-role="button" data-transition="slide">Sign Up</a>
        <a href="forgot.php" data-role="button">Forgot Your Password?</a>
        <p id="validate-status"></p>
    </div>
</div>
</body>
</html>

提交有效凭据后,$message会正确更改为“登录”,因此我知道我在脚本中已经走得那么远了。还尝试了data-ajax="false""true"

1 个答案:

答案 0 :(得分:0)

你好,你可能想把完整的域放在那里。我也有这个问题

header('location: www.yourdomain.com/index.php');

我相信应该做的伎俩