如何在包含php之前執行html?因爲用戶輸入來自html。不應該包含腳本終於?怎麼在包含php的頭文件中執行?
<?php
include('login.php'); // Includes Login Script
if(isset($_SESSION['login_user'])){
header("location: profile.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Form in PHP with Session</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<h1>PHP Login Session Example</h1>
<div id="login">
<h2>Login Form</h2>
<form action="" method="post">
<label>UserName :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>
</body>
</html>
我覺得從上往下讀 –
用PHP包括你主要複製內容的文件並將其粘貼到您已完成包含的位置。如果你希望在你的html之後執行它,只需將你的login.php包含在你的文件末尾。順便說一句,我想你可能應該看看'if(isset($ _ POST [「username」]))' - 因爲如果你的PHP寫得不錯,你不會有任何問題認爲它是,因爲似乎你的PHP鱈魚的一部分執行沒有填寫表格。 – Twinfriends
沒有.... PHP代碼是從上到下執行的(就像在大多數編程語言中一樣),除了對函數的調用以及所有關於控制代碼執行流程的循環.....它不知道或關心首先執行的用戶輸入,甚至不知道該html用於用戶輸入 –