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

    Culver prom limo ..
    In The News:

    Fitness centers and workout studios are starting to establish policies that prohibit shooting phone videos to protect people's privacy.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents
    Apple recently notified a small number of iPhone customers in 92 countries that their phones may be under attack by mercenary spyware.
    An artificial intelligence-powered home security system can fire paintballs and tear gas at trespassers. The camera identifies human faces and animals.
    Technology expert Kim Komando gives her tips and tricks on enhancing your user experience a smartphone and other devices you use everyday.
    A new camera called NUCA uses artificial intelligence to create deepfake photos of subjects by stripping away clothing in close to real time.
    The Kimberley Kube trail-ready camper has a compact but spacious design and combines luxury, functionality and ruggedness for a weekend getaway.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Emails instructing you to reset your password for an account may be legitimate, or they may be scams. Kurt "CyberGuy" Knutsson explains.
    Northrop Grumman's Manta Ray uncrewed underwater vehicle aims to revolutionize undersea missions — it glides through the ocean without human assistance.
    Learn how to work Google's calendar application to streamline and organize your daily tasks from technology expert Kim Komando.
    If you do not want Facebook to have automatic access to your private photos, follow our tips to protect yourself. Kurt “CyberGuy" Knutsson shows you how.
    Kurt “CyberGuy" Knutsson goes into detail about Apple’s recent iOS update that allows iPhone users to instantly translate spoken language simply by using the Action Button.
    Safeguarding your digital life with a reliable physical backup isn't just a precaution, it's a necessity. Kurt “CyberGuy" Knutsson provides the essential backup checklist.
    Kurt “CyberGuy" Knutsson reveals how a Redditor exposed false recycling claims at their apartment, highlighting a report that only 21% of U.S. recyclables are processed.
    Kurt "CyberGuy" Knutsson offers a travel toolkit featuring five technology tools to help you with booking flights and hotels for your summer vacation.
    The bubble behind the clock on your iPhone can appear in different colors. Kurt "CyberGuy" Knutsson explains what each of those colors mean.
    Scammers are using the power of artificial intelligence to mimic voices of people and are using the fake voices to commit crimes, like kidnappings.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Tech guru Kurt "CyberGuy" Knutsson explains the science behind the Invisibility Shield, a 6-foot shield that makes people become invisible.
    The International Olympic Committee on Friday announced plans to use AI in various Olympic aspects, including athlete identification, training and judging.
    Tech guru Kurt "CyberGuy" Knutsson explains an easy trick to avoid squinting while working or surfing the web by zooming in on your personal computer.
    Streaming giant Roku has recently been targeted by a pair of cyberattacks, and the company confirmed over a half million Roku accounts were compromised.
    The Land Aircraft Carrier combines an all-terrain, six-wheeled vehicle with a two-seat aircraft, which features electric vertical takeoff and landing.
    The European Union has sent TikTok a "request for information" on the video sharing platform's newest app, TikTok Lite, under the Digital Services Act, with the aim to clean up social media.

    Cost Effective and Powerful Dynamic Websites w. Fantastico Web Hosting

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

    9 Simple Steps to Create a Background Tiled Image Branded with Your Name

    You have seen those web pages where they have the... Read More

    Why Do I Need A Web Site?

    Even though the Internet has been around for a long... Read More

    7 Killer Ways To Increase Your Online Sales

    Every online entrepreneur I talk to is asking the same... Read More

    How Disabled Users Access The Internet

    In 1995 a new era of accessibility for disabled people... Read More

    Whats Your Business Online Attitude?

    This article was prompted by some customer support work I... Read More

    Database Driven Web Site - Do You Need It?

    Many of site owners still don't realize all advantages of... Read More

    17 Tips to Plan a Website

    Everyone wants one.Everyone wishes they knew how to make one.SOME... Read More

    Make Your Own Brand!

    There are millions and millions of websites on the Internet.... Read More

    How To Evaluate Your Web Sites Performance

    Setting up a website is the very first step of... Read More

    Establishing Your Web Presence

    Part of the success of most home-based businesses is their... Read More

    Is Your Web Site Talking to Your Customer?

    A while ago one of my clients approached me and... Read More

    How Your Own Website Helps Your Small Business Grow

    What do you mean, you don't have a website for... Read More

    Website Globalization

    Globalize Your WebsiteThe Internet has unlocked a wide array of... Read More

    The Importance of Website Stats to You

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

    Websites for Writers ? Why You Need One and How to Get Started Today

    It may seem like the publishing industry's equivalent of Beanie... Read More

    9 Keys to an Effective Website

    Many small companies choose not to invest in a professionally... Read More

    The Web: Your Window of Opportunity

    Thinking about starting up a business? The web is the... Read More

    Trinkets, Lockets And Empty Pockets

    It never ceases to amaze me how many people set-up... Read More

    Maintaining Your Business Website

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

    Website Strategy!

    A website lets you put your products in front of... Read More

    What Does An Ex-Basketball Coach Know About Pulling Web Metrics?

    In my previous life.....Actually, my previous JOB life, I was... 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

    Email Addresses in Web Pages

    You want to give your site's visitors a way to... 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

    Wood Dale limo ..