如何跟踪引用页面以创建其他链接?
我需要能够确定用户刚刚来自哪个页面,以确定要显示哪些链接,例如面包屑或指向上一个下一个项目的链接。 这基本上是 HTTP_REFERER
PHP 中的功能,但我需要一种跨多个页面跟踪它的方法。 我还需要“支持”后退按钮。
我注意到 Facebook 使用“ref”的查询/获取参数来跟踪引用页面。 (他们还避免重新加载整个页面,而是使用 AJAX,但我现在没有预算这样做。)此外,我正在处理的网站需要由 Google 索引,因此此方法也将要求我添加规范链接标记。
我想知道 ref/referrer 查询参数是否是最好的方法或者还有哪些其他选项?
I need to be able to determine which page the user just came from to determine which links to display, such as breadcrumbs or links to the previous next item. This is basically the HTTP_REFERER
functionality in PHP, but I need a way of tracking it across multiple pages. I also need to "support" the back button.
I have noticed that Facebook uses a query/get parameter of "ref" to track the referring page. (They also avoid reloading the entire page, using AJAX instead but I'm don't have the budget to do that right now.) Also, the site I'm working on needs to be indexed by Google, so this method will also require that I add the canonical link tag.
I'm wondering if the ref/referrer query parameter is the best method or what other options there are?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要面包屑,则根本不应该使用
HTTP_REFERER
。 它应该是到达他们所在位置的逻辑路径,无论他们来自哪里,例如User > 专辑> 专辑名称> 照片
,即使它们来自朋友给他们的直接链接。 也就是说,如果您确实想返回几页,只需将它们作为数组存储在SESSION
变量中即可。我很确定 Facebook 只是使用 ref
GET
变量来收集有关用户正在使用哪些按钮的一些统计信息,因为有多种方法可以到达同一页面。所有这些都不应破坏后退按钮,或干扰您的规范标签。
来自评论:您可以使用
?ref=blah
标签或会话变量 ($_SESSION['history'][0] = $_SERVER[' HTTP_REFERER']
或REQUEST_URI
)。 使用你认为最简单的任何东西。 会话变量依赖于 cookie 或通过 URL 传递 ID,GET 只会使 URL 变得混乱,并且可能会传递给朋友。If you want breadcrumbs, you shouldn't be using
HTTP_REFERER
at all. It should be a logical path to get to where they are, no matter where they came from, likeUser > Albums > AlbumName > Photo
, even if they came from a direct link their friend gave them. That said, if you do want to go back a few pages, just store them as a an array in aSESSION
variable.I'm pretty sure Facebook just uses the ref
GET
variable to collect some statistics on which buttons users are using, since there are multiple ways to get to the same page.None of this should break the back button, or intefere with your canonical tag.
From comments: You could use a
?ref=blah
tag, or session variables, ($_SESSION['history'][0] = $_SERVER['HTTP_REFERER']
orREQUEST_URI
). Use whatever you find easiest. Session variables rely on cookies or passing an ID through the URL, GETs just clutter the URL and might get passed around to friends.