Force refresh after back button - help desperatly needed...

  • torstendlp
  • Born
  • Born
  • torstendlp
  • Posts: 4
  • Loc: Mainz, Germany

Post 3+ Months Ago

Hello,
I looking for a way to force the clients browser to refresh a site when the user is hitting the back button.
Example:
User visits page A and goes from there to page B.
Then he is hiting the "back"-Button. Now the browser should not use the page A from cache but load a new page A from the server.
I tried:
Code: [ Select ]
<META http-equiv="Cache-Control" content="no-cache">
<META http-equiv="Pragma" content="no-cache">
<META http-equiv="Expires" content="-1">
  1. <META http-equiv="Cache-Control" content="no-cache">
  2. <META http-equiv="Pragma" content="no-cache">
  3. <META http-equiv="Expires" content="-1">


This works on Netscape but not on IE.

The method I need should work on standard html-pages.
The methos should not use perl or asp.
php is possible.
It should work with sessions.
If possible it should be possible to put the necessary code into the <head> or the <body> of the document.

maybe I specify my problem a bit:
I am running an online shop.
A summary of theshopping cart is shown permanently on each site of my shop.
If somebody adds something to the shopping cart the shopping cart automacally refreshes and shows a new summary of the shopping cart.
If now somebody pushes the back-button in his browser he returns to the last site visited (loaded from his cache) and sees the old version of the shopping-cart summary.
I expect that this can be very disturbing for some visitors.
One specific example:
Somebody visits my site.
He goes to a category of my portfolio.
From this overview he goes to the details of one product. There he adds this product to his shopping cart. The shopping-card summary reloads. so far everything is ok. But now if the user uses the back button to go back to the overview of porducts this overview is reloaded from his cache and with this also the old shopping cart sumary is displayed.....this can be VERY confusing for the customers!


I hope someone of you can help me!

....and sorry for my bad english, it turns rusty since I don't use it so much anymore....

Thank you in advance,

Torsten
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • cjohnweb
  • Born
  • Born
  • cjohnweb
  • Posts: 2

Post 3+ Months Ago

I have the same need for this type of code...I'll post when/if I find the answer. The java wont work well for me in IE, but firefox seams to be ok.

http://www.yuwiex.com
http://www.chibiusa.net
~CJohnWeb
  • cjohnweb
  • Born
  • Born
  • cjohnweb
  • Posts: 2

Post 3+ Months Ago

I have found a solution...somewhat...

So a user is on page A, They click a link and go to page B. Now when they click the back button you want page A to load, but not from cache.

In my situation, it wasn't that I needed the page to refresh, I just needed to redirect the user back an extra page or so.

Here is what I did.

When Page A Loads, I start a session that equals "true", or something like that.

Then when the page is loaded a second time, I check to see if the session has been set or not...or if it is empty. If it is set, then empty the session and redirect the user, otherwise set the session and show them page A.

You could probably use this to redirect the user to the same page, forcing a refresh...but I am not positive on that. See the code below...I have not tested it, just writing it out as I go, so please excuse any errors:

Code: [ Select ]
<?php
session_start();


function msg_redirect($msg,$url,$seconds){

echo "<meta http-equiv=\"Refresh\" content=\"$seconds; URL=$url\">
<center>
<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" width=\"300\">
<tr><td bgcolor=\"999999\">Please Wait....</td></tr>
<tr><td align=\"center\" bgcolor=\"bbbbbb\">
<br /><br />$msg<br /><br />
<a href=\"$url\">Click Here If Your Browser Does Not Support Redirects</a><br />
</td></tr></table><br /><br /><br /><br /><br /><br /><br /></body></html>";
}


if(empty($_SESSION['page_reload']) || !isset($_SESSION['page_reload'])){

$_SESSION['page_reload'] = "true";

}else{

$_SESSION['page_reload'] = "";

function msg_redirect("Refreshing Page...",$PHP_SELF,"0");

}

echo "This is Page A...content...";

?>
  1. <?php
  2. session_start();
  3. function msg_redirect($msg,$url,$seconds){
  4. echo "<meta http-equiv=\"Refresh\" content=\"$seconds; URL=$url\">
  5. <center>
  6. <table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" width=\"300\">
  7. <tr><td bgcolor=\"999999\">Please Wait....</td></tr>
  8. <tr><td align=\"center\" bgcolor=\"bbbbbb\">
  9. <br /><br />$msg<br /><br />
  10. <a href=\"$url\">Click Here If Your Browser Does Not Support Redirects</a><br />
  11. </td></tr></table><br /><br /><br /><br /><br /><br /><br /></body></html>";
  12. }
  13. if(empty($_SESSION['page_reload']) || !isset($_SESSION['page_reload'])){
  14. $_SESSION['page_reload'] = "true";
  15. }else{
  16. $_SESSION['page_reload'] = "";
  17. function msg_redirect("Refreshing Page...",$PHP_SELF,"0");
  18. }
  19. echo "This is Page A...content...";
  20. ?>




Note that in some cases $PHP_SELF may not work if you have variables in the URL. Depending on your situation you can just type in the link you want the user to go to.


Does this help anyone?


http://www.chibiusa.net
http://www.yuwiex.com
http://www.iluvjohn.com
http://www.defreezeme.com
~CJohnWeb

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 56 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.