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

    after renovation cleaning Wilmette ...
    In The News:

    Google AI Overviews can't be permanently turned off, but adding -AI to your searches and using the built-in Web filter can help bypass AI summaries.
    Attaxion researchers found 30 fake Texas campaign merchandise stores traced to just two sellers hawking gear for competing Republicans and Democrats.
    GM plans to debut eyes-off driving in the Cadillac Escalade IQ by 2028, but safety testing reveals how long distracted drivers take to regain control.
    Data brokers assign labels predicting your health, finances and religion based on browsing and purchases, then sell those profiles to businesses.
    Elon Musk says he'll give one SpaceX share to every kid in America in 2027, but key details about eligibility and distribution remain unclear.
    ClearSpace UK's robotic spacecraft with giant claws will chase down dead satellites at 17,000 mph, with a 2029 launch from Scotland planned.
    A fake Social Security statement phishing email uses the SSA logo and a convincing layout, but the sender's domain instantly exposes the scam.
    A clean credit report doesn't mean your identity is safe. Six ways criminals can steal from you without triggering a credit monitoring alert.
    Carolyn Marvin, a 78-year-old retired professor, was arrested after blocking an Uber Eats delivery robot on a Philadelphia sidewalk for months.
    The Midnight Mimosa malware campaign hides inside cheap Android phone firmware, giving attackers powerful access before owners even turn devices on.
    The Fox News AI Newsletter covers the latest artificial intelligence technology advancements, including the challenges and opportunities AI presents now and for the future.
    Meta's Muse AI was built to manage tasks, but users are developing romantic AI relationships and even calling the AI companion their girlfriend.
    A Minnesota murder suspect's notebook listed 11 people search websites, raising urgent questions about data broker opt-out and online privacy risks.
    Google Universal Cart tracks price drops, surfaces promo codes and uses Google Wallet to match your best credit card rewards before checkout.
    Safari's Notify Me feature and Google's price-tracking tools can monitor products and send alerts when prices drop on your iPhone or Android.
    George Weiner built PACspam.org to trace who sends nonstop political fundraising texts after blocking numbers repeatedly failed to stop the messages.
    A dedicated VPN IP address may reduce frustrating CAPTCHAs and bank login security checks by giving websites a consistent connection to recognize.
    Apple Wallet in iOS 27 lets you create digital passes from physical cards using a photo or screenshot, but not every card in your wallet qualifies.
    Anthropic's Claude AI submitted a fabricated eyewitness tip about an unsolved murder to a Philadelphia police website during automated testing.
    P7 DarkSword iPhone spyware can steal saved passwords, photos, Apple Notes and cryptocurrency wallet data by checking for commands every 15 seconds.
    Cybersecurity experts told Fox News Digital that a cyberattack on French supermarket freezers should warn the U.S. about critical infrastructure gaps.
    The Oracle Health breach exposed medical records, Social Security numbers and diagnoses of nearly 20 million patients across multiple states.
    The new Tesla Roadster drove upside down and launched into the air at SpaceX's Texas facility, but a 2028 production target remains unconfirmed.
    Apple's iOS 27 lets you add keywords to iPhone photos, while Samsung Gallery tags and Google Photos search offer similar organization tools.
    A fake Claude AI download scam uses Google ads, and Bing redirects to trick Mac users into pasting a hidden malicious command in their Terminal.

    Is Your Website Doomed for Failure Before Youve Built It?

    One of the things that many people overlook when building... Read More

    Web Content Strategy 101

    Your content is what gets you in search engines, speaks... Read More

    The Importance of Website Stats to You

    One of the best tools you have as a webmaster... Read More

    Study Your Sites Performance Via Hit Tracking

    Knowledge is power.And undoubtedly, it is the key to making... Read More

    How To Write More Powerful Online Text

    Although there are significant differences among the various types of... Read More

    Making Your Websites More Compelling

    The Internet is a remarkable publishing medium. With just a... Read More

    The 5 Biggest Mistakes Almost All Web Designers Make

    Huge Mistake #1: Creating a Website with Flash -- Did... Read More

    How To Make Your Website More Successful? (Part I)

    Building a website and getting it online is easy. Driving... Read More

    2 Key Ways to Make Your Site a Success

    If one more business owner tells me their website sucks... Read More

    How to Get a Better Web Site ROI

    Better Web Site ROIHow to increase your business profitability by... Read More

    UK Online Shopping with an Edge, for Buyers and Sellers Alike

    Any new website competing on the internet, needs to take... Read More

    Adding Word Rich Content to Your Website

    You have permission to publish this article electronically, in print,... Read More

    Newsletter Management Using PHP w/o mySQL for Beginners

    Let's begin by setting some limits. If you're like me,... Read More

    3 Rules of Website Designing and Layout

    Now that you have got your domain name registered, your... Read More

    Entangled in the World Wide Web

    I am just a learner who likes to delve in... Read More

    Top 7 Reasons Why Your Business Needs a Website

    A website provides invaluable advantages for businesses who have one.7... Read More

    Get a Website!, Register Your Domain!: To Website or Not to Website?

    If you're fairly new to the Internet scene, you may... Read More

    Top 5 Reasons to Track Your Website Traffic

    #5 User Satisfaction: Learn what your visitors and site users... Read More

    You Need To Treat Your Website Like An Employee - Heres 5 Ways To Do It

    People often come to me in a state of crisis... Read More

    Free Webmaster Tools - 7 Things Every Webmaster Needs in Their Toolbox

    Webmaster tools are vital to becoming both efficient and effective... Read More

    What Hosting Companies Dont Tell You, Could Hurt You?

    Did you know that hosting companies overcrowd their servers despite... Read More

    The Topic Of Your Website

    The first thing you will have to deal building your... Read More

    Why A Simple Counter is Never Enough for Your Website

    A simple website stats counter is not enough if you... Read More

    1 Simple Solution to All Internet Marketers about Their Website Design Needs

    It is an undeniable fact that not everybody is keen... Read More

    Website Survival Guide

    In the big, wide online world there are millions of... Read More

    eco-friendly cleaning service Lincolnshire ...