PHP 登录页面重定向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19782194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Login Page Redirect
提问by user2896254
this code is incomplete and I need it to redirect to a page called mainpage.php with hardcoded information for the username and password. Here's the code.
这段代码不完整,我需要它重定向到一个名为 mainpage.php 的页面,其中包含用户名和密码的硬编码信息。这是代码。
<?php
session_start();
$username="user";
$password="123";
if($_POST['username'] == $username && $_POST['password'] == $password)
?>
<html>
<head>
</head>
<body>
<div style='text-align:center'>
<h3>Welcome To Kontak</h3>
</div>
<hr /><br />
<form id='login' action="" method='post' accept-charset='UTF-8'>
<fieldset style="width:550px">
<legend>Admin Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >UserName:</label>
<input type='text' name='username' id='username' maxlength="50" />
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='submit' value='Submit' />
</fieldset>
</form>
</body>
</html>
回答by Vijay Kumar
I think you are looking for this:
我想你正在寻找这个:
if($_POST['username'] == $username && $_POST['password'] == $password)
header( 'Location: mainpage.php' );
?>
so the header will take to mainpage.php when if condition is satisfied. --Vijay
所以如果条件满足,标题将转到 mainpage.php 。--维杰
回答by Anto
Have to start and end the if block
必须开始和结束 if 块
<?php
session_start();
$username="user";
$password="123";
if(isset($_POST['username']) && $_POST['username'] == $username && $_POST['password'] == $password)
{
header("Location: your_page.php");
}
else
{
?>
<html>
<head>
</head>
<body>
<div style='text-align:center'>
<h3>Welcome To Kontak</h3>
</div>
<hr /><br />
<form id='login' action="" method='post' accept-charset='UTF-8'>
<fieldset style="width:550px">
<legend>Admin Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >UserName:</label>
<input type='text' name='username' id='username' maxlength="50" />
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='submit' value='Submit' />
</fieldset>
</form>
</body>
</html>
<?php
}
?>
回答by Suresh Kantharaj
Change 'header("Location: your_page.php");' to 'header("Location: mainpage.php");'
更改 'header("位置:your_page.php");' to 'header("位置:mainpage.php");'