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

    residential cleaning services Lincolnshire ..
    In The News:

    House Bill 469 would prevent AI systems from owning property, serving as executives, or gaining legal personhood in Ohio under Representative Thaddeus Claggett's proposal.
    Public voter records expose retirees' personal details to election scammers who create targeted cons using names, addresses, and voting history data.
    Instead of fearing what comes next with artificial intelligence, think outside the box. Here are high-earning AI jobs that don't require a computer science degree.
    OpenAI CEO Sam Altman says polite words like "please" and "thank you" cost millions annually, while direct prompts may improve ChatGPT accuracy by several points.
    Chattee Chat and GiMe Chat exposed intimate conversations and photos, revealing users spent up to $18,000 on AI companions before the breach.
    New Instagram parental controls allow families to manage teen screen time and content limits through the Family Center with stricter safety settings.
    Third-party security breach at Discord exposes sensitive user information including government IDs, highlighting cybersecurity risks from external service providers.
    Survey of 1,000 students shows teens using AI for personal relationships while two-thirds of parents remain unaware of their children's AI usage.
    Cybersecurity experts warn about a ShadowLeak vulnerability that weaponized ChatGPT's Deep Research agent to steal personal data from Gmail accounts through hidden commands.
    Tesla's Full Self-Driving system faces federal investigation following 58 reports of crashes, with six vehicles running red lights before colliding with other cars.
    The Fox News AI Newsletter brings you the latest developments on artificial intelligence, with news on OpenAI moving to soon allow erotica for adult users.
    Eric Schmidt alerts that hackers can reverse-engineer AI models to bypass safety measures, citing examples like the jailbroken ChatGPT variant called DAN.
    Cybercriminals exploit Microsoft Teams through impersonation, malicious links and fake profiles to gather intel and deliver ransomware to personal and work devices.
    Google, Dior, Allianz and dozens of other companies lost sensitive customer data in Salesforce-related breaches affecting millions of records across multiple sectors.
    Apple launches iOS 26 with new Preview app that combines document editing, PDF annotation and scanning features into one streamlined iPhone experience.
    New AI road monitoring system uses sensor-embedded fabric to predict infrastructure problems, potentially reducing maintenance costs and traffic disruptions for cities.
    Holiday charity scams target retirees through lookalike organization names, untraceable payment requests, and data broker information to steal donations.
    The Federal Trade Commission says criminals are posing as IRS agents, law enforcement officers or other officials, often over the phone or online, to steal thousands of dollars at a time.
    AI phishing scams now use voice cloning and deepfake technology to trick victims, but Kurt "CyberGuy" Knutsson reveals warning signs to watch for.
    Inversion Space unveils Arc, a reusable reentry vehicle that can deliver up to 500 pounds of cargo from orbit to anywhere on Earth in under an hour.
    Red flags like processing fees, urgent countdowns and requests for full Social Security numbers expose fraudulent settlement sites targeting consumers.
    Comprehensive analysis of Google Maps, Waze and Apple Maps examines usability, routing accuracy, data handling and features across the top navigation platforms.
    Expert analysis reveals whether wired Ethernet or wireless Wi-Fi connections are safer for home internet use, plus practical steps to secure your network from attackers.
    Australian construction robot Charlotte uses sand, crushed brick and recycled glass to 3D print fireproof, floodproof homes with reduced carbon footprint.
    Cybercriminals are using fake invitation emails to trick recipients into downloading malware and stealing personal information and data.

    Abandonment - Why Visitors Don?t Turn Into Customers

    Every good Internet business understands the value of conversions versus... 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

    5 Essential Traits Of A Home Business Website

    So you've decided to start an online work at home... Read More

    How to Draw Icons or Images on a Mapserver Generated Map

    In this example I have used the map of the... Read More

    What Business Owners MUST Know BEFORE They Commit To Having A Web Site

    Q1.Why would I need a web site? A1.- Improve my... Read More

    So You Want To Have A Website

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

    Tips for Building a Great Business Website

    A website is lifeline of internet home business. In order... Read More

    How Improving Your Sites Usability Can Increase Your Buyers by 40% and Boost Each Order By 10%!

    With all of the factors involved in designing and building... Read More

    Are Web Graphics Stealing Your Money?

    They might not be wearing a mask and carrying a... Read More

    Improving Usability for Screen Reader Users

    Simply ensuring your website is accessible to screen reader users... Read More

    Sticking To Your Plan

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

    Maintaining Your Business Website

    QUESTION: Should I build and maintain my business Web... Read More

    Get Your Business on the Web

    I can't think of any business alive today that couldn't... Read More

    From Concept to Website

    You've decided to create a website to market your products... Read More

    Earning From Your Website

    Before you start building your site, ask yourself "WHY?". Why... Read More

    Is Your Website Doomed for Failure Before Youve Built It?

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

    Website Content & Usability

    Writing for the web is totally different to writing for... Read More

    Revealing the Firefox Secret Used by Top Web Developers and Power-Browsers

    Profiles are one of the best kept secrets around regarding... Read More

    You Dont Know Which One

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

    Do You Really Need A Website To Succeed

    Rosalind wants to share her inspirational poetry with a wider... Read More

    5 Ways to Build a Website

    If you are like me you have wanted to build... Read More

    Beyond Web Usability: Web Credibility

    If you've been developing websites on Mars for the past... Read More

    HTML Editors 101 - Smaller Is Better

    SiteSpinnerSiteSpinner is a user-friendly web site development tool that includes... Read More

    Create Huge Income From Your Web Site - 10 Easy Ways

    The cost of setting up a web site is dirt... Read More

    Guidelines for Web Page Optimization

    Below, I have listed 8 simple steps that you can... Read More

    best cleaning company Highland Park ..