<?php //密碼設定為123,php的語法在網頁運行時,檢視原始碼中不會顯示,無需擔心 if(isset($_POST[password])){ $passward = $_POST[password]; if($passward == '123'){ setcookie("login",'USER', time()+3600); //將網址改為登入成功後要導向的頁面 header("Location: home.php"); } } ?> Please enter the password:<br> <form name="form" method="post" action="index.php"> <input type="password" id="password" name="password"></input><br> <button>ENTER</button> </form>
可以放在任意位置,如果他人直接進到home.php此網址,也會需要重新移轉到登入畫面index.php
<?php if(!isset($_COOKIE["login"])){
//將網址改為要導入的登入頁面
header("Location: index.php");
}
?>