创建“来自”导航-PHP
我想知道,如何才能获取用户在我的网站上访问的最后 X 个页面的示例?
我正在创建一个导航,以便用户可以轻松地看到他仅在我的网站上访问过的 X 个页面。
我只是不知道该怎么做。 PHP中有没有函数可以获取这个?
提前致谢。
I was wondering, how is it possible to get example the last X number of pages a user came from on my site?
I am creating a navigation, so the user easily can see the X number of previuos pages he visited on my site only.
I just don't know how to do this. Is there any function in PHP to obtain this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您指的是网站上的最后 X 个页面,并且您知道如何使用会话和数组。
在这种情况下,您可以为用户初始化一个会话,然后每次用户访问页面时,将 URL 或该页面的某些标识附加到数组中。如果数组中有超过 X 个页面,请另外删除第一个页面。
然后您可以获取数组的内容,将它们解析为一堆链接并将它们显示在您的网站上。
如果您在进入网站之前指的是页面,则只能通过引用标头获取最新页面。然而,某些浏览器可能被配置为不发送引用标头,因此实际上没有办法正确完成此操作。
I'm assuming you mean the last X pages on your site only, and that you know how to use sessions and arrays.
In this case you could initialize a session for the user, then every time the user visits a page, append the URL or some identified of that page to the array. If there's more than X pages in the array, additionally remove the first one.
Then you could just get the contents of the array, parse them into a bunch of links and show them on your site.
In case you meant the pages before entering your site, you can only get the latest one via the referer header. Some browsers might be configured to not send the referer header, however, so there really isn't a way of accomplishing this properly.
$_SESSION['history']
现在是一个索引数组,其中包含用户在您网站上的所有历史记录。$_SESSION['history']
is now an indexed array with all of the user's history on your website.