views:

265

answers:

1

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 cononical link tag.

I'm wondering if the ref/referrer query parameter is the best method or what other options there are?

+2  A: 

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, like User > 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 a SESSION 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'] or REQUEST_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.

Mark
I'm not sure I get what you are saying. No, I know I can't use the sesion because people not view any other pages before viewing a page. I know I can't use the HTTP_REFERER. So, are you saying that the ref tag is the best or something else is? You seem to say everything is wrong.
Darryl Hein
What are you trying to do exactly? If you want to keep the last 5 pages a user has viewed, put them in a session variable. If you want breadcrumbs, then generate them based solely on the current page they are at, regardless of where they've been. In my example, if a user is viewing a photo, you could display the breadcrumbs like `User > Albums > AlbumName > Photo`. You don't need HTTP_REFERER or anything for that, just some programming logic.
Mark
I'm saying that Facebook doesn't use the ref tag to generate links at all. They're using it to monitor how visitors are using their site so they can determine which buttons are being clicked the most. Nothing to do with breadcrumbs.
Mark
Well, in some cases, breadcrumbs are affected by where you came from. Lets say, you find a picture of someone through Person X's profile, but the picture is on Person Y's profile. The links at the top *should* show links back to Person X, not Person Y, so you can easily navigate back to Person X (without the back button).
Darryl Hein
Well, in that case you *could* use a ?ref=blah tag, or session variables like I've mentioned, ($_SESSION['history'][0] = $_SERVER['HTTP_REFERER'] or REQUEST_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.
Mark
I have accepted your answer because of your last comment. The actual answer doesn't really answer the question.
Darryl Hein