0

每当我进入一个页面,即登录页面或任何其他页面时,我都想将页面的名称保存在一个$_SESSION变量中。

登录页面:

<?php
    session_start();
    $_SESSION['page'] = 'login.htm';    
?>

它仅适用于登录页面,不会覆盖其他页面,例如主页:

<?php
    session_start();
    $_SESSION['page'] = "home.htm"; 
?>

我需要会话变量'page'来保存我的最后一页,有人可以帮忙吗?

4

4 回答 4

3

Why not just use $_SERVER['HTTP_REFERER']? This will give you the previous page in PHP, without having to add anything to sessions.

于 2013-02-27T16:59:26.047 回答
1

If all you need is default "back" functionality you should let the browser handle it.

If what you want is something to be used as a breadcrumb following some internal order (or path in a tree) my advice is to let each page "know" the path that leads to it.

If you really need to know from what page the user came from save it to a previous variable before you write over the current variable.

// Make sure user didnt just refresh the page
if ($_SESSION["current"] !== "currentPage.php") {
  $_SESSION["previous"] = $_SESSION["current"];
  $_SESSION["current"] = "currentPage.php";
}
于 2013-02-27T17:10:55.723 回答
1

当您导航到新页面时,首先检索保存的“后退”变量(并在后退链接/面包屑或其他内容中使用它),然后用当前页面覆盖会话“后退”变量,以便为下一个页面做好准备移动 =)

于 2013-02-27T17:01:49.990 回答
0

You're using different keys.. 'page' and 'back'.

于 2013-02-27T16:59:30.897 回答