Index Pages - Back Button in Browser
I made detail/master pages in php for my site. When a user uses the back button in the browser, the whole page is regenerated and they lose where they were on the page.
Ebay is a great example of what I'm talking about. Their index pages are huge, yet the page isn't completely regenerated from the database if they leave the index.
Is there a way to code the index pages so that when they go back, they can go back to the same area on the index page that they were viewing before?
Thanks in advance!
Triexa.com posted this at 15:50 — 10th October 2007.
They have: 173 posts
Joined: Feb 2005
Could you please explain a bit more about what it is you want to achieve? I don't completely follow you...
L3ZL1E posted this at 17:17 — 10th October 2007.
They have: 32 posts
Joined: Feb 2007
I have index (master) pages that list items and breif descriptions of them. Those links go to details pages for the items, where all of the details of that item are listed. When you go from the index page to the details page, and press the back button in the browser, the items are queried and listed again, from the very first item. Therefore, if the user goes from the index to the details page and uses the back button in the browser, the user has to look over the list of items again and find where they were before, by scrolling down the page. I don't want them to have to scroll back to where they were.
In contrast, I've noticed that static pages do what I want them to do, that is, go right back to the place on the index where the user last viewed.
Does that make more sense?
pr0gr4mm3r posted this at 18:51 — 10th October 2007.
He has: 1,502 posts
Joined: Sep 2006
I think this is because their browser isn't caching the page, and it's being reloaded every time. Here are a couple of ways you can fix this.
1) Set the cache time of the page (assuming PHP). Set the 'expires' date to some point in the future.
<?php
header(\"Expires: Mon, 26 Jul 1997 05:00:00 GMT\");
?>
2) Instead of having the site visitors use their back buttons, provide a link where they can go back like "< Back to List of Items". Then, use an anchor tag to make that link go to the correct spot in the page. The back link should point to a location like http://www.example.com/items.php#item12345
L3ZL1E posted this at 19:11 — 10th October 2007.
They have: 32 posts
Joined: Feb 2007
Is it possible to make a date variable for the header and then set the cache to expire in, say, 24 hours? I don't want to keep updating the expiration date/time.
pr0gr4mm3r posted this at 19:34 — 10th October 2007.
He has: 1,502 posts
Joined: Sep 2006
Yup, this should do it.
<?php
/* create timestamp in the future */
$future = strtotime('+7 Days');
/* format it to be sent to the header */
$future_formatted = date('D, d M Y H:i:s T', $future);
/* send cache header */
header(\"Expires: ' . $future_formatted . '\");
?>
L3ZL1E posted this at 11:27 — 11th October 2007.
They have: 32 posts
Joined: Feb 2007
Thanks so much for your help! This will help me out a lot!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.