另一个javascript重定向

另一个javascript重定向,javascript,php,Javascript,Php,我的看法是: <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"

我的看法是:

<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>";
    }
if(isset($\u POST['login'])){
$username=$_POST['inputUsername'];
$password=$\u POST['inputPassword'];
echo“window.location.href='collections.php';”;
}
当我点击按钮时, 它没有将我重定向到collections.php,我在这里错过了什么?

您从php重定向

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

使用php标题重定向页面,与您在此处所做的操作相比更容易、更好。
标题('位置:')

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

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

您的php控制器是否触发?这不是重定向用户的正确方法。使用
标题('Location:collections.php',true)
。它将使用HTTP头而不是JavaScript重定向用户,JavaScript实际上可以被禁用或抑制。您使用的是什么框架?是codeigniter吗?请添加一些解释