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

    executive chauffeured services Bradford .. Madison to Airport car
    In The News:

    Getting virus alerts on your iPhone? Tech expert Kurt “CyberGuy" Knutsson helps you learn how to handle fake scam alerts and boost security.
    Tech expert Kurt “CyberGuy" Knutsson says opening emails is safe, but risks arise from interacting with links, attachments or HTML content.
    Tech expert Kurt “CyberGuy" Knutsson reveals four signs of compromised Social Security numbers and offers five steps to protect yourself.
    Tech expert Kurt “CyberGuy" Knutsson discusses how MAB Robotics' Honey Badger 4.0, a versatile robot, now walks underwater with amphibious skills.
    An updated Android trojan called FakeCall hijacks bank calls. Tech expert Kurt “CyberGuy" Knutsson says Android phone manufacturers and Google need to step up their game on security.
    The Massimo Modular E9 is a sleek, smart and comfy tiny home in 409 square feet. Tech expert Kurt “CyberGuy" Knutsson takes a closer look at what the future of housing might look like.
    Every stock trader should consider a virtual private network to safeguard their trading, according to tech guru Kurt "CyberGuy" Knutsson.
    Apple recently announced its new lineup of Macs and rolled out Apple Intelligence, its latest artificial intelligence-powered feature for its products.
    A Swiss-engineered robot can climb ladders, showing why it's at the cutting edge of autonomous robotic solutions for harsh industrial settings.
    Kurt "CyberGuy" Knutsson presents the cities targeted most by robocalls, why this is happening and what you can do about it to protect your privacy.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents
    Kurt "CyberGuy" Knutsson shares tips and suggestions for how to get the best use out of the updated Calendar app available with the latest iOS update.
    Your Social Security number, your unique identifier used for many purposes, has likely been leaked on the Dark Web; here are some steps you can take to protect yourself.
    Researchers have developed a new technology that creates strong, sticky fibers capable of lifting objects and capturing things from a distance.
    Smart rings track the same things that smartwatches do, including steps, sleep and a general overview of your overall health, and they tend have more battery life than smartwatches.
    Researchers have developed a robotic finger that can perform routine medical exams like those conducted by doctors, helping to address the growing shortage of trained professionals.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Insurance administrative services company Landmark Admin reported that a data breach from a May cyberattack affected over 800,000 people.
    Sotheby's will auction the first artwork created by Ai-Da, the world's first robot artist created in 2019 by British gallerist Aidan Meller.
    More than 250 million users of the Verizon Messages app will have to switch to another app. Verizon is shutting down Messages in the next month.
    Tech expert Kurt “CyberGuy" Knutsson provides a list of 10 celebrities who are the most targeted by deepfake scams, including Tom Hanks.
    Tech expert Kurt “CyberGuy" Knutsson discusses how Vast's Haven-1, launching in 2025, transforms space living with human-centric design.
    UnitedHealth confirms over 100 million Change Healthcare users had their data stolen. Kurt “CyberGuy" Knutsson reveals what happened and what caused the breach.
    Tech expert Kurt “CyberGuy" Knutsson explains how iOS 18 brings new text formatting and animated effects to the Messages app.
    Whether you're a social media veteran or novice, Facebook friend request scams are common. Kurt the CyberGuy provides tips to keep your account safe.

    Business Website Building Do?s and Don?ts

    First, using a lot of web graphics, flash, banners and... Read More

    The Dos and Donts of Launching a Small Business Website

    Launching a new small business website is often a long... Read More

    Trust Us! Sending Credible Messages

    A company must earn and keep trust or sales don't... Read More

    Warning: The Truth About Having a Web Site!

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

    The Cost Of A Web Site

    Just starting out, you can start with a simple informational... Read More

    Web Site Promotion: How To Advertise Your Website For Profits

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

    Building a Great Intranet Taxonomy

    While it may seem like a "quick and easy" task,... Read More

    7 Ways to Gain a Professional Online Reputation

    A professional online reputation is essential to the flourishing of... 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

    How to Increase Sales with Automation Improvements

    How popular is online shopping? And is there room for... Read More

    Lead Generation How to -- 10 Tips On Generating More Internet Sales Leads

    Many millions of dollars are being wasted on promoting and... Read More

    Duplication vs. Individualism

    How can we add Word Rich Content to our Websites... Read More

    Ecommerce for Beginners

    Like most average persons, I wanted some extra money to... Read More

    Entangled in the World Wide Web

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

    The Top Ten Benefits of Having a Web Site

    Do you need a web site? Are you considering getting... 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

    Ten Major Tips to Develop a Multilingual Web Site to Work

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

    Earn On Offshore Web Design and Development

    If you have some experience in web site design and... Read More

    Creating Websites that Cater to Exam Preparations

    One of the things that Internet excels is disseminating information... Read More

    How to Handle Web Surfers Who Disabled JavaScript

    There are hundreds of millions of Web surfers today. Each... Read More

    CPanel Fantastico - Features and Benefits

    Fantastico is a 3rd-party cPanel add-on and can be purchased... Read More

    FREE Amber Alert Tickers for Your Website

    Project Safekids provides webmasters a valuable tool which could save... Read More

    3 Essential Tools Every Website Designer and Marketer Needs

    Appealing to others is really important when you have a... Read More

    5 Essential Traits Of A Home Business Website

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

    Why Your Brick-and-Mortar Biz Needs A Website

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

    O'Hare Chicago prom limo ..