如何使用会话在页面之间导航



我们能写这样的东西来让代码真正发挥作用吗。

<?php 
if (isset($_SESSION['u_id'])) {
header("Location: profile.php");
} 
else {
header("Location: index.php");
}
?>

你是说代码不起作用吗?脚本需要首先使用session_start((来访问会话变量。。

您必须在每页的顶部添加session_start();。如果不是,就不能是。

示例:

<?php 
session_start();
if (isset($_SESSION['u_id'])) {
header("Location: profile.php");
} 
else {
header("Location: index.php");
}
?>

最新更新