我正在创建一个登录页面,该页面接受用户名,然后重定向用户登录。目前已完成,并使用以下 Java 脚本。
function process()
{
var url="https://example.com/users/profile" + document.getElementById("username").value;
location.href=url;
return false;
}
<p>Enter your username</p>
<form onsubmit="return process();">
<input type="text" name="username" id="username">
我更愿意在不使用 Java Script 的情况下执行此操作,以支持禁用它的用户、旧浏览器并将其从页面的源代码中隐藏。无论如何,子目录都受到保护,但我只想增加兼容性。
我正在尝试用 PHP 来做到这一点;
<form action="/authenticate.php">
<input type="text" name="username" id="username">
我正在使用相同的表单,但创建了一个名为的页面authenticate.php。所有authenticate.php包含的是;
<p>Authenticating…</p>
<?php
$username = ["username"];
header("Location: https://example.com/users/profile/$username"); die();
?>
如果steve是输入,我希望然后重定向到https://example.com/users/profile/steve但它没有。我已经设置了重定向来处理错误,并且表单无论如何都会将文本转换为小写。
我只是想知道为什么;
<?php
$username = ["username"];
header("Location: https://example.com/users/profile/$username"); die();
?>
添加到 URL 后将无法使用,但在没有 的情况下可以使用,$username因此这是唯一的错误。我也试过,$username = $POST_["username"];但这不相关,似乎也不起作用。当前代码带我到https://example.com/users/profile/Array
如果有人可以就正确的方法提供建议,我将不胜感激。