我正在尝试制作一个登录页面,人们只需键入他们的用户名,然后将用户名作为变量重定向到网址。 这应该都是在没有从另一个文件中获取内容的情况下发生的。
就像那样,表单的动作将是php与提交按钮中的变量重定向。
我不是很喜欢PHP编程但是知道基本的HTML和一些jquery,所以如果有人能给我复制/粘贴到我的索引文件中的代码,那就太棒了。
谢谢
更新: 实际上,我已启动并运行登录系统,但它位于用户自己的导演中。 因此,主页面上的表单应该加载用户名并将其粘贴为服务器上的其他目录。
答案 0 :(得分:1)
将表单用作" GET"!
<form action="login.php" method="get">
</form>
然后您的输入名称将是变量。所以:
<form action="login.php" method="get">
<input type="text" name="username"/> <br/>
<input type="submit" value="Go!"/>
</form>
此表单将重定向到:
login.php?username=The username which you gave
答案 1 :(得分:0)
输入正确的用户名和密码后,在提交登录页面后,您可以在$_SESSION['username']=$_POST['username']
中设置用户名。
要重定向到另一个页面,您需要在下面写一行:
header('Location: http://www.example.com/dashboard');
exit;
示例:将以下文件另存为login.php
<?php
session_start();
if(isset($_POST['username']) && isset($_POST['password']))
{
//// you need to write some code over here to get password verification from database based on username is entererd
//// i.e. $data = $db->mysql_query();
if()//write some code here if password is verified then allow to login and enter into system
{
$_SESSION['username']=$_POST['username'];
header('Location: http://www.example.com/dashboard');
exit;
}
}
?>
它唯一的逻辑。您需要进行一些更改并在最后编写代码。
答案 2 :(得分:0)
<?php
if(isset($_POST['action']) && $_POST['action']!="")
{
if(isset($_POST['username']) && $_POST['username']!="")
{
header('Location: some_other_page.php?username='.$_POST['username']);
exit;
}
}
?>
<form action='index.php' method='post'>
<input name='username' type='text' value='' placeholder='Insert username here'>
<input type='submit' value='Go' name='Go'>
<input type='hidden' name='action' value='do_redirect'>
</form>