它应该如何工作:Index.php 是受保护的页面。它包括 check.php,它检查您是否有一个会话 = 好。如果没有,你没有登录 -> 注销,删除会话。但它不起作用,它总是注销,就像我没有登录一样......
索引.php
include ‘check.php’;
echo "logged in";
检查.php
session_start();
if($_SESSION[‘login’] != ‘good’) {
unset($_SESSION[‘login’]);
unset($_SESSION[‘name’]);
header(‘Location: login.php?logoff’);
exit();
}
登录.php
if(isset($_POST[‘login’])) {
$gb = array();
$gb[‘user1’] = ‘pass1’;
$gb[‘user2’] = ‘pass2’;
if(isset($gb[$_POST[‘username’]]) && $gb[$_POST[‘username’]] == $_POST[‘password’])
{
$_SESSION[‘login’] = ‘good’;
$_SESSION[‘name’] = $_POST[‘name’];
header("Location: index.php");
} else {
header("Location: login.php?wrongpass");
}
} else { ?>
Login Form
<?php } ?>
我希望有一个人可以帮助我!