Preventing Repeat Form Submission Using PHP Sessions

We've all seen those messages on some websites warning not to click a button more than once or negative consequences, like paying a bill twice, may result. Sometimes we can cause these problems by hitting the back or refresh buttons. In this article I will explain a methodology whereby a site can ensure each form is submitted only once, thereby demonstrating that such warnings are unnecessary and, depending on the nature of the problems caused, worth repairing immediately. Let's begin by taking a look at the process we are studying: Form Submission. As pedantic as it may seem, it will be worthwhile to detail each of the steps in this process:

  • Visitor requests a page from the server which has a form on it.
  • Server retrieves form and sends to user.
  • User enters data on form and submits to server.
  • Server processes form data and returns resultant page.
  • The scenario we now need to analyze is when the user re-triggers a previous form submission process. What we need to find or create is something which changes during the form submission process which does not depend on the specific form being submitted and which we can tell changed. That was a loaded sentence which fully details our solution, so let's break it down. Find or create something which
  • changes during the form submission process,
  • does not depend on the specific form being submitted, and
  • we can tell changed.
  • Since the item which changes does not depend on the form being submitted (e.g. it doesn't matter if it's a newsletter registration form, customer signup form, payment form, etc.), the item is not something which already exists and therefore must be created, so let's create a form variable called submissionId and assume it has the 3 properties mentioned above. So far, so good -- or so it appears! The third "property" is that "we can tell [it] changed", but "changed" is not a property of a variable, so we need to look at this more closely. In order to tell something changed, we must have a reference point, an answer to the question "changed from what?" This is where a session variable will come into play. If we define a session variable, say $_SESSION['nextValidSubmission'] and treat it as a reference point, we will have all of the tools necessary to protect our visitors. The idea will be to keep the session variable updated with the last submissionId sent out and change the submissionId each time it is sent out to the user. Then, if they try to resubmit the data, they will be submitting an old submissionId which doesn't match nextValidSubmission and we will know not to re-process this data. Let's look at this in terms of the processes:

  • Visitor requests a page from the server which has a form on it.
  • Server retrieves form, generates a new submissionId which is embedded into the form, updates nextValidSubmission, and sends to user.
  • User enters data on form and submits to server.
  • Server processes form data, changes nextValidSubmission, and returns resultant page.
  • Now, if the visitor somehow resends the data, they will be sending the old submissionId which will not match the new nextValidSubmission. So, you can now say goodbye to relying on javascript to remove/disable buttons, silly warning messages, and upset customers by preventing form re-submission.

    Webmaster of script reference - The *NEW* PHP Reference & Tutorial Site For Non-Programmers
    script reference

    maid service near Mundelein ..
    In The News:

    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Miami-Dade debuts America's first autonomous police SUV with AI cameras, drone deployment and real-time crime detection in groundbreaking law enforcement pilot.
    Bank impostor scams cost Americans $2.9 billion as criminals use AI voices and caller ID spoofing to steal life savings. Learn nine essential fraud protection tips.
    Foreign-owned apps secretly harvest personal data from seniors, making them prime targets for scams. Learn how to protect your privacy and stop data brokers today.
    Sens. Josh Hawley and Richard Blumenthal introduce bipartisan GUARD Act to protect minors from AI chatbots through mandatory age verification and disclosure requirements.
    Ghost-tapping scammers exploit wireless technology to drain accounts through small transactions, but RFID-blocking wallets and transaction alerts can protect you.
    French pilot project demonstrates wireless charging roads that can deliver over 300 kilowatts of power to EVs while driving, potentially eliminating range anxiety.
    YouTube's Ghost Network spreads information-stealing malware through thousands of fake videos offering cracked software, using compromised accounts and fake engagement.
    Protect your privacy by disabling your smart TV microphone. Most TVs have hidden mics that listen even when voice commands are off. Learn quick steps to stop unwanted audio capture.
    SessionReaper vulnerability hits Magento and Adobe Commerce stores, compromising 250+ sites in one day. Hackers steal data and hijack shopping sessions.
    Master essential parental controls and digital safety tools to protect your kids online. Learn screen time limits, location settings and privacy controls every parent needs.
    Cybersecurity expert shares six essential steps to protect against dark web threats, including data removal services, password managers and antivirus software.
    NVIDIA GPU space mission could revolutionize cloud services by enabling orbital data centers that make apps, games and AI tools faster and more efficient.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Microsoft warns Windows 10 users face serious security risks as 90% of ransomware attacks target unsupported systems. Learn why upgrading to Windows 11 is crucial.
    Nike unveils Project Amplify, revolutionary motorized shoes developed with Dephy that add powered assistance to every step for runners and walkers.
    Cybersecurity experts warn about one of the largest credential compilations ever found, urging users to check "Have I Been Pwned" and change passwords immediately.
    Quick iPhone and Android battery optimization techniques help your device stay powered all day by turning off hidden features that secretly drain power in the background.
    Kodiak Driver autonomous truck achieves perfect 98 safety score, matching top human fleets in groundbreaking AI evaluation by Nauto's VERA system.
    New 401k catch-up contribution rules in 2026 will change taxes for high earners over 50. Learn how scammers exploit these changes and protect your retirement savings.
    Kurt Knutsson's guide covers social media privacy protection through location settings, account privacy controls and two-factor authentication to prevent scams and data breaches.
    Revolutionary retinal implant restores central vision in 80% of patients with advanced macular degeneration, offering hope where treatments once only slowed blindness.
    Learn how to use passkeys on Windows and Mac computers without cameras or fingerprint readers. Discover secure authentication methods that replace passwords.
    Tesla's FSD v14.1.2 update reintroduces Mad Max mode, enabling higher speeds and more frequent lane changes than the standard Hurry profile setting.
    A phishing email scam targeting American Express customers shows how cybercriminals use fake urgent messages to steal personal and financial information.

    How to Get Your Website In Front of Thousands of Customers At No Cost To You!

    Dan Kennedy once said that if you can't make money... Read More

    Internet Marketing Website Promotion -The 7 Biggest Mistakes I See People Make With Websites!

    1. Many people are not getting good or complete advice.... Read More

    Flash Deadly Sins (That Can Kill Your Web Business)

    Looks like every client wants a Flash site these days... Read More

    How One Word Or Even One Letter Can Boost Conversion Rates By Over 400%!

    Recently I was reviewing the keyword specific conversion rate data... Read More

    How To Evaluate Your Web Sites Performance

    Setting up a website is the very first step of... Read More

    Profitable Websites for Exclusive Industries

    In the region where my company is located, South Bend,... Read More

    Web Sites ? Should I Learn or not?

    A common dilemma most small and medium businesses face when... Read More

    The Power Is In The Pipes: How To Get Maximum Leverage From Your Website

    What is the most important part of your online business?Many... Read More

    You Cant Just Build A Website And Hope It Works!

    Like any area of business your website needs some effort... Read More

    Pick Up Your Own Domain Name

    Think up a name and check if yourname.com is available.... Read More

    Is Your Web Site Talking to Your Customer?

    A while ago one of my clients approached me and... Read More

    How Web Templates Are Helping Online Businesses to MultiplyTheir Income

    Web templates by nature are created to aid and ease... Read More

    Writing Effective ALT Text For Images

    Anyone who knows anything about web accessibility knows that images... Read More

    Ten Major Tips to Develop a Multilingual Web Site to Work

    If you are living in a country that its native... Read More

    Topics to Add When Creating an Alternate and Modern Medicine Web Directory

    Alternate medicine finds its own place in the hearts and... Read More

    Building eCommerce Websites that Work - Part 3

    An interesting eCommerce success factor that isn't precisely overlooked, but... Read More

    6 Steps To Your Own Website

    A lot of people these days are interested in getting... Read More

    Successful Commercial Sites

    Do you make your website just to entertain yourself or... Read More

    10 Things You Should Be Monitoring On Your Website

    Every business needs to know how it is doing. That's... Read More

    Web Accessibility Myths

    With more and more countries around the world passing laws... Read More

    Product Promoting: Getting The Response

    When you publish a content site there are times when... Read More

    A Network Of Web Sites Is Not Enough!

    The big thing these days is your ability to capture... Read More

    Track Your Visitors, Using PHP

    There are many different traffic analysis tools, ranging from simple... Read More

    Sticking To Your Plan

    So you have a good idea for a business and... Read More

    Instant Relevant Web Site Content - No Its Not a Bot

    In about the Time it takes to Watch a Reality... Read More

    high-end home cleaning Bannockburn ..