为什么 "exit" 导致页面根本不显示,同时回显“ ”完成工作?

why does "exit" , causes page not to display at all, while echoing " " gets the job done?

我正在学习php,我想知道为什么第6行的exit;会导致页面全白,而第7行的echo " ";会按预期工作。 这是代码:

<?php 
 if ($_POST['username']=="user" && $_POST['password']=="password") {
    header("Location: game.html");
}
else {
  //(if i write exit on this line, i get all white page)  exit;
  // (if i echo empty string the site works ok)     echo "";
} ?>


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

    <h3 style="text-align: center">რეგისტრაცია</h3>

    <div style="margin: 0 300px 0 300px">
    <form action="index.php" method="post">
    მომხმარებელი: <input type="text" name="username" value=""><br />
    პაროლი: <input type="password" name="password" value="" style="margin-left: 47px"><br/>
            <input type="submit" name="submit" value="შესვლა" style="margin-left: 170px">
     </form>
     </div>

</body>

这是我的实际网站 - 用于学习目的http://nikolozasatiani.com/,登录后随时享受游戏:D 用户名:用户密码:密码

语言构造 exit 停止执行,即下面的所有内容(在您的情况下是 HTML)永远不会发送到输出缓冲区,因为 PHP 不会解析过去的任何内容那一点。

然而,当执行 echo " "; 时,您只是在页面上打印一个 space。在您的示例中,您可以省略 else-部分,因为它什么都不做:

if ($_POST['username']=="user" && $_POST['password']=="password") {
    header("Location: game.html");
}

实际上,由于在 if 语句中只执行了一行,如果您更喜欢这种语法,也可以省略大括号。我个人认为它看起来更干净:

if ($_POST['username']=="user" && $_POST['password']=="password")
    header("Location: game.html");