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

    personalized cleaning services Des Plaines ..
    In The News:

    Petco disclosed a data breach exposing customer Social Security numbers, financial account details, and driver's license information due to a software error.
    Baseball teams can now analyze complete swing mechanics in normal training environments using Theia's markerless AI system that processes standard high-speed footage.
    Smart home hacking fears overblown? Expert reveals real cybersecurity risks and simple protection tips to keep your connected devices safe from hackers.
    MIT develops needle-free glucose monitor using light technology. Revolutionary device could replace painful finger pricks for diabetes management.
    The ClickFix campaign disguises malware as legitimate Windows updates, using steganography to hide shellcode in PNG files and bypass security detection systems.
    Researchers from Osaka Metropolitan University designed a 21-foot dome that combines aquaculture and hydroponics to create a self-sustaining urban food system.
    The Fox News AI Newsletter gives readers the latest AI technology advancements, covering the challenges and opportunities AI presents.
    ChatGPT data breach exposes personal info of users through partner Mixpanel. OpenAI confirms names, emails compromised in security incident.
    Android rolls out Emergency Live Video for 911 calls, letting dispatchers see real-time scenes during emergencies. Great for holiday travel safety.
    Malicious Chrome and Edge extensions collected browsing history, keystrokes and personal data from millions of users before Google and Microsoft removed them.
    Google's new Call Reason feature lets Android users mark calls as urgent before dialing, displaying an urgent label to recipients using Phone by Google app.
    Medical history made as surgeons successfully restore sight to legally blind patient using world's first 3D printed corneal implant grown from human cells.
    Data brokers aggressively collect your holiday shopping data to fuel scams and targeted ads. Learn how to delete your digital profile before 2025 starts.
    Scammers are sending fake MetaMask wallet verification emails using official branding to steal crypto information through phishing links and fraudulent domains.
    Learn what background permissions, push notifications, security updates, auto-join networks and app refresh mean to better manage your phone's privacy settings.
    Criminals test stolen data by applying for deposit accounts in victims' names to prepare bigger attacks. Learn why banks won't share fraud details.
    New study of 10,500+ kids reveals early smartphone ownership linked to depression, obesity, and poor sleep by age 12. Earlier phones mean higher risks.
    A phone phishing attack compromised Harvard's alumni and donor database, marking the second security incident at the university in recent months.
    AutoFlight's zero-carbon floating vertiport uses solar power to charge eVTOL aircraft while supporting emergency response, tourism, and marine energy maintenance.
    A new phone return scam targets recent buyers with fake carrier calls. Learn how criminals steal devices and steps to protect yourself from this fraud.
    New Anthropic research reveals how AI reward hacking leads to dangerous behaviors, including models giving harmful advice like drinking bleach to users seeking help.
    The Fox News AI Newsletter gives readers the latest AI technology advancements, covering the challenges and opportunities AI presents.
    Holiday email scams, including non-delivery fraud and gift card schemes, spike in November and December, costing victims hundreds of millions, the FBI says.
    Holiday visits offer the perfect opportunity to help older parents with technology updates, scam protection and basic troubleshooting skills for safer digital experiences.
    Swiss scientists create grain-sized robot that surgeons control with magnets to deliver medicine precisely through blood vessels in medical breakthrough.

    The Number 1 Reason Most Websites Fail

    Failure, just like success, is measured differently by each and... Read More

    If You Build It, They Will Come?

    Building a new website can be a lengthy task. From... Read More

    Six Basic Reasons Why Visitors Stay On Your Web Site

    1. The first page appears quickly.It's a good way to... Read More

    Your Website Reflects Your Business

    Some left shoes are in isle 5, while the right... Read More

    Sticking To Your Plan

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

    Growing Your Meetings In CyberSpace

    As increasing numbers of people search for information on the... Read More

    WYSIWYG Versus Coding: HTML With A Purpose

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

    How to Make Your Own Website For Free

    If you like the Internet and surfing through the billions... Read More

    What ROI You Should Expect From Your Web Site

    Is Your Web Site an Expense or an Investment?Why don't... Read More

    How Does Your Website Make Me Feel?

    When people think about the Internet, they think about technology.... Read More

    Why You Need A Web Site

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

    New Years Resolutions: Is Improving Your Website One of Them?

    With the New Year upon us yet again, it's time... Read More

    Let Marketing Manage Your Website Content

    The definition of the phrase "Content Management" depends on what... Read More

    Where on Earth is Your Websitee?

    You've just finished congratulating your marketing team. After six months... Read More

    Effectively Using Robots Meta Tags

    The "robots" meta tag, when used properly, will tell the... Read More

    Planning Your Website for Success

    Most people know they need a website in order to... Read More

    What is SQL?

    What is SQL? SQL stands for Structured Query Language and... Read More

    2 Key Ways to Make Your Site a Success

    If one more business owner tells me their website sucks... Read More

    Server Side Includes (SSI) with ASP

    Server Side Includes (SSI) with ASP People often... Read More

    Be Creative Before You Purchase Or Create A Website

    Before you jump into spending coutnless hours on designing and... Read More

    Marketing Your Business Online

    As a business you can't afford to ignore the Internet... Read More

    Website For The Company Store

    If your company own one or more stores, you might... 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

    Do You Really Need A Website To Succeed

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

    1 Simple Solution to All Internet Marketers about Their Website Design Needs

    It is an undeniable fact that not everybody is keen... Read More

    family-safe home cleaners Arlington Heights ..