简体   繁体   English

用户查看的最近5个页面名称

[英]Last 5 Page Names User Viewed

I'm trying to code the last 5 page names the user viewed on my site and produce it into a list. 我正在尝试对用户在我的网站上查看的最后5个页面名称进行编码,并将其生成一个列表。 I'm currently able to get the current page name, but I don't know how to get the previous pages. 我目前可以获取当前页面的名称,但是我不知道如何获取之前的页面。 This is the code I'm using to get the current page name: 这是我用来获取当前页面名称的代码:

<?php
    $pageName = basename($_SERVER['PHP_SELF']);
    echo $pageName;
?>

PHP Sessions should get you going in the right direction. PHP会话应该使您朝着正确的方向前进。 For example: 例如:

session_start();

if(!isset($_SESSION['pages'])) {
    $_SESSION['pages'] = array();
}
if(count($_SESSION['pages']) < 5) {
    $_SESSION['pages'] []  = $_SERVER['PHP_SELF'];
} else {
    echo "Limit reached";
}
print_r($_SESSION['pages']);

I recommend you use PHP Sessions to accomplish this. 我建议您使用PHP会话来完成此任务。

So, save the current page name that you want to the sessions variable like so: 因此,将所需的当前页面名称保存到session变量中,如下所示:

<?php
    $pageName = basename($_SERVER['PHP_SELF']);
    $_SESSION['pageName'] = $pageName;
?>

And then continue to save these names. 然后继续保存这些名称。 @Len_D just beat me to the punch with an answer that uses arrays and is likely what you need. @Len_D通过使用数组的答案击败了我,这很可能是你所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM