另一个javascript重定向


another javascript redirecting

我的视图:

<div class="container">
    <form class="form-signin" method="post" action="">
        <h2 class="form-signin-heading">Admin Login</h2>
        <input type="text" id="inputUsername" name ="inputUsername"
               class="form-control" placeholder="Admin" required autofocus />
        <label for="inputPassword" class="sr-only"> Password</label>
        <input type="password" id="inputPassword" name="inputPassword"
               class="form-control" placeholder="Password" required />
        <br/>
        <button class="btn btn-lg btn-primary btn-block" name="login"
                type="submit">Login</button>
    </form>
</div>

我的控制器:

    if (isset($_POST['login'])) {
        $username = $_POST['inputUsername'];
        $password = $_POST['inputPassword'];
        echo "<script>window.location.href = 'collections.php';</script>";
    }

当我点击按钮时,它不会将我重定向到collections.php,我在这里错过了什么?

使用php头重定向页面,这很容易而且更好地与您在这里所做的进行比较。页眉('位置:http://www.example.com/');

您从php 重定向

<?php 
    if (isset($_POST['login'])) {
        $username = $_POST['inputUsername'];
        $password = $_POST['inputPassword'];
        header('Location: collections.php'); //<------- php redirect to other page
    }
?>

这就是您试图在PHP中输出JS以进行重定向的原因如果您使用相对,请小心url

$redirectURL = "../controller/collection.php";
print("<script>");
print("var t = setTimeout('"window.location='".$redirectURL."';'", 3000);");
print("</script>");