Jump to content

Detecting/Disabling back button using PHP - reload page when back button pressed


dbgohan

Recommended Posts

Hello,

 

I was wondering if there is a way to disable or detect when a user presses the browser back button in PHP.

 

What I want to do is that when a back button is pressed, the page reloads.

 

Please let me know if there is a way to do this. If any of you use modernbill, it has that feature.

 

Thanks

Link to comment
Share on other sites

Actually I could see that being REALLY annoying, depending on what exactly you're doing...

But maybe you can use JavaScript's onUnload event? E.g.:

<BODY onUnload="window.location.href=thisPage.html;"> 

Hope that helps...

 

What I am trying to do is this. For example if a client wants to update his/her info, they modify the info in the form and press the update button, the script then updates their info in the database and notifies the user. Now lets say they press the back button to go back to the modify page, what I want to do now is rather than display the information in the form that was there before (chaching) I want the script to retrieve the real data from the database and display it in the form.

 

I Hope that is clear.

 

Thanks

Link to comment
Share on other sites

I think I see what you mean. Here's what I found on http://us3.php.net/header:

PHP scripts often generate dynamic content that must not be cached by the client browser or any proxy caches between the server and the client browser. Many proxies and clients can be forced to disable caching with:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?> 

If you put something like that at the top of the page you don't want to be cached (before you begin output), maybe that will do the trick.

Link to comment
Share on other sites

That does not seem to work. When I press the back button, it gives me the page expired error.

 

Error: ---------------

 

Webpage has expired

 

  Most likely cause:

The local copy of this webpage is out of date, and the website requires that you download it again.

 

  What you can try:

    Click on the Refresh button on the toolbar to reload the page. After refreshing, you might need to navigate to the specific webpage again, or re-enter information. 

 

    More information

 

If you continue to have this problem, try the following:

 

In Internet Explorer, click Tools, click Internet Options, and then click the Advanced tab.

Scroll down and uncheck the "Do not save encrypted pages to disk" option in the Security settings.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.