PHP之会话session
程序员文章站
2024-03-20 13:55:46
...
通过全局变量来判定是否设置session相关值
<?php
session_start();
if (! isset($_SESSION['username'])) {
if (isset($_POST['username'])) {
$name = $_POST['username'];
if ($name == '123') {
$_SESSION['username'] = $_POST['username'];
echo "Welcome!<br/>";
} else {
require_once 'login.html';
}
} else {
require_once 'login.html';
}
} else {
echo "you have logged!<br/>";
session_unset();
}