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

    move in cleaning service Wilmette ..
    In The News:

    Privacy risks are hiding in plain sight, as your personal data is likely being collected, tracked, and sold without your knowledge.
    VenHub, a fully autonomous, AI-powered smart store just opened at the LAX/Metro Transit Center in Los Angeles.
    A woman's Facebook account takeover reveals dangerous social engineering tactics and provides lessons on recovery, avoiding scams and enacting stronger security measures.
    Shanghai engineers are using 432 walking robots to relocate a complex, preserving Shikumen architecture while creating space for a modern underground hub and cultural center.
    Major healthcare data analytics firm Episource had a cybersecurity incident exposing 5 million patients' medical records and personal information in recent breach.
    A new sophisticated PayPal scam sends legitimate-looking emails from official PayPal addresses, using phone numbers instead of links to convince victims to download remote access tools.
    Fox News' AI Newsletter brings you the latest on this rapidly evolving technology.
    The innovative Kara Pod device extracts moisture from air to create mineral-rich water and brew coffee, featuring UV sterilization and compatibility with Nespresso pods.
    Gov. Hochul unveiled New York's nuclear power plant project to power a million homes, which faces permit challenges while promising jobs and a cleaner energy future.
    SAFE introduces Aerie, an underground luxury bunker combining high-end living with advanced security, wellness amenities and interactive walls simulating panoramic views.
    A Facebook scammer posing as Elon Musk tricked a victim with promises of a Tesla and $250,000, requesting gift cards that become untraceable once the codes are shared.
    Experience hands-free golfing with the Robera Neo smart caddie that uses AI to follow you, navigate obstacles and carry your clubs with GPS course mapping.
    Cybersecurity alert: 16 billion passwords exposed in massive credential database affecting major platforms. Protect your accounts with password managers
    The innovative BeBot robot uses electric power to remove pollution from shorelines, covering 20-30 times more area than manual collection while preserving wildlife.
    A new ClickFix campaign targets macOS users with fake Spectrum support sites, tricking victims with CAPTCHA failures to paste commands that install information-stealing malware.
    AI-powered autonomous trucks from Plus Automation are being tested across the U.S., Europe and Asia to solve logistics challenges while facing regulatory hurdles and labor concerns.
    Your health information might feel private and secure with your doctor, but the reality is far more complicated. Data brokers collect a wide range of sensitive health data, from diagnoses and prescription details to personal identifiers, and sell this data to marketers, insurers, and other third parties.
    Kepler Robotics has officially introduced its Forerunner K2 "Bumblebee" humanoid robot at the SAIC-GM automotive plant in Shanghai, marking a significant moment in the real-world deployment of advanced robotics.
    Scammers never seem to be running out of new ways to try and get their hands on your money – and lately, they've been getting sophisticated.
    Thirty people were injured and killed, though the exact number remains currently unknown, when a suicide bomber blew himself up in a Damascus church.
    Unexpected password reset alerts signal potential hacking attempts or phishing scams. Learn how to respond and establish stronger security measures for your accounts.
    A historic electric airplane flight landed at JFK with passengers, marking a milestone as Beta Technologies demonstrates the practicality and efficiency of electric air travel.
    The Chaos ransomware group breached Optima Tax Relief in a double-extortion attack, stealing sensitive customer case files and corporate documents with personal information.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    The first human brain-computer interface by Paradromics was completed in 20 minutes, featuring microelectrodes to help paralyzed individuals control computers with thoughts.

    Are You Being Scammed By Your Web Design Company?

    This is a growing concern amongst many business owners. Does... Read More

    Five Steps to Create Your Software Product with Outsourcing

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

    For Newer Sites, Web Marketing Depends On Titles & Links!

    We all start out the same. Some have budgets, some... Read More

    The Topic Of Your Website

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

    Getting One-way Inbound Links: the 5 Major Strategies

    With search engines putting a damper on direct reciprocal links,... Read More

    Web accessibility for screen magnifier users

    The needs of screen magnifier users are overlooked when implementing... Read More

    Web Site Promotion: How To Advertise Your Website For Profits

    Making money with your web site is the dream and... Read More

    Art, Artists and the Web: Part 3--What to Put on an Artist?s Website

    What to put your the website if you are an... Read More

    Why You Need A Web Site

    "I have a small business with just a couple of... Read More

    Introductory PHP For Non-Programmers

    When you started reading this sentence you assumed lo acabar?a... Read More

    Warning: The Truth About Having a Web Site!

    If you don't have a web site yet, are thinking... Read More

    The Problem with Automated Accessibility Testing Tools

    An automated accessibility tool is a piece of software which... Read More

    Why Your Brick-and-Mortar Biz Needs A Website

    The internet has taken over our lives with a vengeance,... Read More

    Your Website Should Be Selling

    It may come as some surprise to a traditionally off-line... Read More

    Web Site Optimization: How To Speed Up Your Web Site By Minimizing Your GIF and PNG Image Bit-Depth

    Are bloated images slowing down your web site and causing... Read More

    Have You Got Your Ear To The Ground Or Your Head In The Sand?

    What happened on your website yesterday? What about last week... Read More

    Making Your Website Shine! Attract and Keep Visitors at Your Site!

    When you consider the billions of individuals and companies on... Read More

    Better Web Site ROI: Efficient Online Business with SEO, PPC, Split Testing, and Forums

    If you're looking for better web site ROI, chances are,... Read More

    Website Development: Become Your Own Expert

    Starting and maintaining a business is challenging enough without the... 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

    Remember This When Building A New Site - Beginners Guide

    I recently helped my mom to launch a website (www.mom2me.com)... Read More

    Why Your Business Needs a Website

    Even with the steady growth of the World Wide Web,... Read More

    Why Every Small Business Owner Needs Two Websites

    Every small business owner knows that they need a website,... Read More

    Increase Hits to Help Increase Your Business

    In this day and age most businesses consider having their... Read More

    Web Content: How Much Should I Pay?

    When web content gets discussed on webmaster bulletin boards, the... Read More

    green cleaning service Lincolnshire ..