当我包含PHP代码时,浏览器中不显示任何内容

时间:2014-05-04 17:11:03

标签: php html

学习php和我正在通过php构建简单的登录表单但是在我运行代码之后,白色屏幕进入浏览器,甚至html部分也没有显示在浏览器中。

    <?php 
    function redirect($location )
    {
header("Location: " . $location);
    }
    exit;?>
    <?php
    if (isset($_POST["submit"])) {
if ($username == "s9iper1" && $password == "secret") {
 redirect("https://www.facebook.com/bil30als?ref=tn_tnmn");
} else{
$username = $_POST["username"];

$message  = "loggin {$username}";
    }
    }
else{
$username = "";
$message = "there were some errors.";
    }

    ?>

<!DOCTYPE html>
<html>
<head>
<title>second page</title>
</head>
<body>
<?php echo $message;?>
<form action="form_single.php" method="post" >
Username: <input type="text" name="username" value="<?php echo htmlspecialchars($username);
?>"/><br>
Password: <input type="password" name="password" value="">
<br>
<input type="submit" name="submit" value="submit">
  </form>
  </body>
  </html>

3 个答案:

答案 0 :(得分:0)

这是完整的代码吗? 如果是,则缺少开始标记

答案 1 :(得分:0)

我重写了整个代码,因为它有太多错误;)

<?php 
    function redirect($location )
    {
        header("Location: " . $location);
        exit;
    }

    if (isset($_POST["submit"])) {
        $username = (string) $_POST["username"];
        $password = (string) $_POST['password'];

        if ($username == "s9iper1" && $password == "secret") {
            redirect("https://www.facebook.com/bil30als?ref=tn_tnmn");
        } else{
            $username = (string) $_POST["username"];

            $message  = "loggin {$username}";
        }
    }

    if (empty($message)) $message = '';
?>
<!DOCTYPE html>
<html>
    <head>
        <title>second page</title>
    </head>
    <body>
        <?php echo $message; ?>
        <form method="post" >
            Username: <input type="text" name="username" value="<?php echo htmlspecialchars($username);?>"/><br>
            Password: <input type="password" name="password" value="">
            <br>
            <input type="submit" name="submit" value="submit">
        </form>

    </body>
</html>

答案 2 :(得分:-1)

我假设它不起作用的原因,是您要求从不同文件进行验证。 如果您发布的代码位于index.php中,则表单也需要从index.php请求验证。

<form action="index.php" method="post" >