简体   繁体   English

成功登录后重定向JQueryMobile登录页面

[英]JQueryMobile Login Page Redirect on Successful Login

Trying to redirect a user to index.php after they login successfully. 成功登录后尝试将用户重定向到index.php。 I have everything working except the redirect. 除重定向外,我所有工作正常。 Been looking around for about an hour now and no luck..I'm sure it is tied to jQueryMobile owning the page 我已经环顾了大约一个小时,而且没有运气。我确定它与拥有该页面的jQueryMobile有关

Have tried 试过

header('Location: index.php');  

nothing happens. 什么都没发生。

Also tried 也尝试过

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

Both do a re-direct if I make them the first part of my php code, but when placed where I need it they do nothing. 如果我将它们设置为我的php代码的第一部分,它们都将进行重定向,但是当放置在我需要的位置时,它们什么也不做。

Here is my code: 这是我的代码:

<?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>

When valid credentials are submitted the $message does correctly change to "Logged in" so I know that I am getting that far in the script. 提交有效的凭据后, $message确实会正确更改为“已登录”,因此我知道我在脚本中已经做到了这一点。 Have also tried with data-ajax="false" and "true" 也尝试过使用data-ajax="false""true"

Hello you may want to put the full domain in there. 您好,您可能想在其中放置整个域。 I had this problem too 我也有这个问题

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

I believe that should do the trick 我相信应该可以解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM