将下面代码放在主页面(index.php)最上端 (html的前面)
<?php
session_start();
$check = "hello";
if(isset($_POST['name'])&& isset($_POST['pass'])){
if(strlen($_POST['name']) < 1 && strlen($_POST['pass']<1)){
$failure = "Enter Username & Password.";
}
else{
if($check==$_POST['pass']){
$_SESSION["pass"]=$_POST["pass"];
$_SESSION["name"]=$_POST["name"];
header("Location: home.php?");
return;
}
else{
echo("Incorrect Password !");
}
}
}
在 实际真实页面 访问页面(home.php)也增加这么一段代码
<?php
session_start();
if($_SESSION["pass"]){
unset($_SESSION["pass"]);
}
else{
header('Location: index.php');
exit;
}
暂无评论