我试图通过设置密码保护页面来保护它。我正在使用下面的代码,但它不起作用。
主页.php
session_start();
// Process the POST variables
$username = $_SESSION["user_name"];
//$password = $_POST["password"];
// Set up the session variables
$_SESSION["user_name"] = $username;
if(!isset($_SESSION['user_name'])) { header('Location: login.php'); die('<a href="login.php">Login first!</a>'); }
login.php 的相关部分
<?php
session_start();
// Process the POST variables
$username = $_SESSION["user_name"];
//$password = $_POST["password"];
// Set up the session variables
$_SESSION["user_name"] = $username;