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

    one time home cleaning Highland Park ..
    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.

    Maximizing ROI via Web Site Traffic Analysis

    We are clearly well past the innocent "golden age" of... Read More

    6 Steps To Your Own Website

    A lot of people these days are interested in getting... Read More

    Where on Earth is Your Websitee?

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

    You Need a Website!

    No matter the size of your business, having a web... 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

    Beautiful Web Sites Seldom Make More Sales

    Designing an E-commerce Web site is not as simple as... Read More

    Are You Losing Sales Because of These 4 Simple Website Mistakes?

    Losing website sales and traffic is sometimes simply a case... 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

    Does Your Business Really Need A Website?

    Website, website, website, everyone says you need one. But do... Read More

    4 Steps to Selling More With Your Web Site

    Most web sites are more like stage sets than real... Read More

    Five Reasons You Have to Stop Your Web Site

    That's right. Your method, behavior and strategy you are now... 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

    What Works and What not Works for Your Internet Business

    "Build it and they will come."--Filed of Dreams (1989) If... Read More

    Planning A Usable Website: A Three-step Guide

    A website is like an information flow, with you as... Read More

    Entangled in the World Wide Web

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

    Learn to Build a Better Online Business Website Using Keywords and Content

    Are you aware that 90% of the websites on the... Read More

    What and How to choose the Right Keywords for Mega Traffic

    Keywords in Search Engine Optimizing and Search Engine Marketing are... Read More

    5 Essential Traits Of A Home Business Website

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

    What YOU Should Know Before Getting A Web Site!

    Everyday thousands of new businesses make the leap and take... Read More

    Why to Have a Website for Your Company

    After having decided to start a business, the next thing... Read More

    Why Local Service Companies Should Have a Website

    The Internet is being used by local service business to... Read More

    Benefits Of An Accessible Website: Part 1 - Increase In Reach

    The DDA (Disability Discrimination Act) states that service providers must... Read More

    5 Tips For A Better Website

    Having an eye catching website is great, but are you... Read More

    Ten Ways NOT to Set Up a Website-based Service Business

    1. As the first step, "Hire a web designer."First create... Read More

    The Evolution Of Search

    There have been many significant changes to the face of... Read More

    licensed cleaning services Park Ridge ..