Jump to content


Preventing browser refresh from reposting form values -- cache_limiter?

  • Please log in to reply
1 reply to this topic

#1 macworks

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 April 2006 - 09:19 PM

I'm wondering how to prevent a page refresh from re-posting the form values so that PHP won't re-process the same form submission twice.

For example, I'm building my own custom message board and when a poster submits their new post, they get the result page which shows that their message was successfully posted. But if they refresh the browser window, they'll end up posting the message again.

Is this where session.cache_limiter comes in?

I realize I could send another header once the post has been logged into the DB in order to forward on to yet another page (preventing this refresh scenario) but I'd prefer a slightly easier method of preventing the refresh from happening altogether.

#2 Ninjakreborn

  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 22 April 2006 - 01:37 AM

I ahve had this problem before on other websites. Maybe you could use javascript, unless php does it, to disable the refresh button for that one specific page only, it will prevent people from refreshing the page, then you could leave a little message there saying that the button has been disabled to prevent double posting.
you can use one of the following scripts I tracked down for you to stop the refresh and f5 buttons from functioning in that window, if one doesn't work try the other, the second has been tested in some of the newer browsers, so pick and choose. Or use them all for double effect I guess.

This is javascript code by teh way./
if (document.all){         
    document.onkeydown = function (){
            var key_f5 = 116; // 116 = F5        
        if (key_f11==event.keyCode){
                            alert("F5 pressed");
                return false;

function showDown(evt) {
        evt = (evt) ? evt : ((event) ? event : null);
        if (evt) {
            if (event.keyCode == 8 && (event.srcElement.type != "text" 
&& event.srcElement.type != "textarea" && event.srcElement.type !
= "password")) {
                // When backspace is pressed but not in form element
            else if (event.keyCode == 116) {
                // When F5 is pressed
            else if (event.ctrlKey && (event.keyCode == 78 || 
event.keyCode == 82)) {
                // When ctrl is pressed with R or N

    function cancelKey(evt) {
        if (evt.preventDefault) {
            return false;
        else {
            evt.keyCode = 0;
            evt.returnValue = false;

    // Additional code for NS
    if (navigator.appName=="Netscape") {
    document.onkeydown  = showDown;
If you know javascript then you might want to make sure you put necessary tags while you go, like the <script language="javascript" type="text/javascript">
or you might be able to just stick those in the header section.


Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users