1

此代码不完整,我需要将其重定向到名为 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>
4

3 回答 3

5

我想你正在寻找这个:

if($_POST['username'] == $username && $_POST['password'] == $password)

header( 'Location: mainpage.php' );
?>

因此,如果条件满足,标头将转到 mainpage.php。——维杰

于 2013-11-05T05:16:11.400 回答
1

必须开始和结束 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
}
?>
于 2013-11-05T05:09:01.220 回答
0

更改 'header("Location: your_page.php");' 到'标题(“位置:mainpage.php”);'

于 2013-11-05T05:21:28.293 回答