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

    tidy up service Glenview ..
    In The News:

    New Android malware BankBot YNRK silences phones, steals banking data and drains crypto wallets automatically. Learn how this advanced threat works.
    FDA approves first human trial for Paradromics' brain-computer interface that could restore speech for paralyzed patients through neural technology.
    New phishing platform QRR targets Microsoft 365 users across 1,000 domains in 90 countries. Learn how to spot fake login pages and protect your accounts.
    OpenTable now uses AI to track your dining habits and share insights with restaurants. Learn what data they collect and how to protect your privacy.
    Google's discontinued Nest thermostats still secretly upload home data to company servers despite losing smart features, raising serious privacy concerns.
    New Android malware NGate steals NFC payment codes in real-time, allowing criminals to withdraw cash from ATMs without your card. Learn protection tips.
    DoorDash confirms data breach exposing customer names, emails, addresses after social engineering attack. Learn how to protect yourself from scams.
    Concerned about Google's AI scanning your Gmail? Learn how to disable Gemini features that access your emails, Drive files and Chat messages for privacy.
    Google warns Android users about dangerous fake VPN apps hiding malware that steals passwords, banking details and personal data from phones and tablets.
    Apple's digital passport feature lets iPhone users breeze through TSA checkpoints this holiday season using Digital ID technology at 250+ airports.
    A new phishing scam targets family photos with fake "Cloud Storage Full" alerts. Criminals steal credit card information through fake sites. Learn protection tips.
    South Korean scientists create ultra-thin fabric muscles that turn clothes into robotic assistants, lifting 33 pounds while weighing under half an ounce.
    Archer Aviation has acquired Hawthorne Airport for $126M to launch an LA air taxi network ahead of the 2028 Olympics, featuring AI-powered eVTOL operations and next-gen aviation tech.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Fake AI apps disguised as "ChatGPT" and "DALLĀ·E" are flooding app stores with dangerous malware that steals data and monitors users without detection.
    Fake buyers demand specific vehicle reports from unknown sites to steal credit card information from car sellers, but warning signs can help identify these scams before paying.
    Android users can now manage apps across multiple devices more easily with Google Play Store's updated remote uninstall button in the latest update.
    NASA's Perseverance rover discovers shiny metallic rock on Mars that could be a meteorite from an ancient asteroid, containing high levels of iron and nickel.
    Holiday scams spike during Black Friday and Cyber Monday as criminals exploit your leaked personal data. Learn how to protect yourself from fake stores and phishing.
    Commerce Department proposes TP-Link router ban over Chinese security risks. Learn how this potential prohibition could affect your home network and devices.
    Hyundai AutoEver America suffered a data breach affecting 2,000 current and former employees, exposing names, Social Security numbers and driver's license information.
    Washington court rules automated license plate reader images are public records, even when stored by vendors like Flock Safety, setting precedent for transparency.
    Fake airline texts claiming flight cancellations are targeting travelers with convincing scams. Learn how cybercriminals steal personal data and credit card info.
    Discover how iOS 26's new Adaptive Power feature automatically extends iPhone battery life by learning your usage patterns and adjusting performance intelligently.
    New TikTok malware campaign tricks users into running PowerShell commands that download Aura Stealer, which steals credentials and authentication tokens.

    Website Sales: 10 Reasons Why People Dont Buy From You

    You've put up a website to promote a product or... Read More

    Web Site Development Process - The Life-cycle Steps

    A system development process can follow a number of standard... Read More

    Credibility - 10 Ways to Build it on Your Website

    If you have your own business website and you are... Read More

    Cost Effective and Powerful Dynamic Websites w. Fantastico Web Hosting

    If you are developing your website on a host that... Read More

    Are You Overlooking the Benefits of Using Sub-Domains within Your Web-hosting account?

    One of the most useful features offered by some web... Read More

    10 Things You Should Be Monitoring On Your Website

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

    The Internet Road Map

    1) Data CaptureOne easy way to collect e-mail addresses and... Read More

    Writing Effective ALT Text For Images

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

    4 Marketing Tips for Resourceful Webmasters!

    The internet is a sea of knowledge. Getting your information... Read More

    Five Steps to Create Your Software Product with Outsourcing

    Many executives and investors are skeptical that software products can... Read More

    Web Analytics - Getting it Right

    Understanding and using web analytics.In recent years, website marketers were... Read More

    Why Local Service Companies Should Have a Website

    The Internet is being used by local service business to... Read More

    Pick Up Your Own Domain Name

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

    Guide to Internet Business - Design and Content

    After deciding what kind of internet business you want to... Read More

    What Works and What not Works for Your Internet Business

    "Build it and they will come."--Filed of Dreams (1989) If... Read More

    Creating a Sticky Web Site

    When used to describe a web site, the term "sticky"... Read More

    Should You Design Your Own Website?

    If you're anything like most small business owners, you probably... Read More

    So You Want To Have A Website

    So you want to have a website. You have gone... Read More

    Launch Your Own Website Today - Its Easier Than You Think!

    Thousands of people are now making a living online and... Read More

    WYSIWYG Versus Coding: HTML With A Purpose

    After years of working with entrepreneurs who developed their first... Read More

    Develop a Solid Website Presence

    Starting an internet business can be confusing to non-veterans. The... Read More

    Build or Buy a CMS?

    Creating a content management system either from scratch,... Read More

    Benefits Of An Accessible Website: Part 2 - The Business Case

    The DDA (Disability Discrimination Act) states that service providers must... Read More

    Top 5 Reasons to Track Your Website Traffic

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

    You Dont Know Which One

    I still remember it very clear ... It was almost... Read More

    full-service cleaning Mundelein ..