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

    Wood Dale Chicago prom limo .. Lockport Chicago limo O’Hare
    In The News:

    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents
    Internet browsers are useful, but they can be dangerous. Clicking on malicious links can direct you to dangerous websites that steal information or infect your device.
    Apple's latest iOS update introduces advanced artificial intelligence capabilities, which may be capturing and analyzing sensitive information.
    Breach site confirmed 56,904,909 Hot Topic users' data leaked online. Tech expert Kurt “CyberGuy" Knutsson says the company's silence makes matters even worse.
    Tech expert Kurt “CyberGuy" Knutsson discusses how an innovative Easy-Way kit turns standard strollers electric, simplifying navigation for parents.
    Tech expert Kurt “CyberGuy" Knutsson talks about T-Mobile being hacked in broad cyberattack on global phone and internet companies.
    Tech expert Kurt “CyberGuy" Knutsson shows you how to add, customize and manage widgets for quick access to apps and info from your iPhone home screen.
    Wrong Google searches can not only compromise your device and personal data. They can also bring law enforcement to your doorstep. Hackers are targeting Google searches.
    China's Shanghai Kepler Robotics has developed a new humanoid robot that can carry up to 35 pounds per hand for commercial applications across various industries
    Checking your hearing has gotten easier with the new hearing test feature in AirPods Pro 2. You can take reliable hearing tests using your iPhone or iPad.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Kurt "CyberGuy" Knutsson explains how a VPN — virtual private network — works and how running it can slow down the operation of your device.
    The WalkON Suit F1, an exoskeleton developed to help people with disabilities, can actually walk over to a person in a wheelchair, solving a major problem.
    ClickFix, a new scam targeting computer users, is on the rise in the U.S. The scam prompts its targets to click on a link to fix a problem.
    Skydweller is the world's largest unmanned solar-powered aircraft that can stay airborne for weeks, and even months, without refueling.
    The U.S. government said it is investigating after People's Republic of China hackers targeted commercial telecommunications service providers in the U.S.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Scammers are using increasingly sophisticated ways to lure unsuspecting victims, and some are impersonating an email help desk or support team.
    You can unsend or edit your iMessages with the latest iOS updates. Kurt the CyberGuy explains how you can save yourself some potential embarrassment.
    Kurt “CyberGuy" Knutsson says there’s been a rise in cybercriminal services using hacked police and government emails to send subpoenas and data requests to U.S. companies.
    Kurt “CyberGuy" Knutsson discusses how Axiom Space and luxury designer Prada are collaborating on NASA's Artemis III spacesuit design.
    Voice assistants may cause confusion across devices. Tech expert Kurt “CyberGuy" Knutsson offers some solutions to fix it.
    Shameless scammers trick veterans into giving personal info or cash. Tech expert Kurt “CyberGuy" Knutsson explores five common scams.
    Tech expert Kurt “CyberGuy" Knutsson helps you honor our heroes with these powerful podcasts, audiobooks and documentaries this Veterans Day.

    Maximizing ROI via Web Site Traffic Analysis

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

    Email Addresses in Web Pages

    You want to give your site's visitors a way to... Read More

    Ever Wondered What Challenges Other People With Their Web Site?

    Have you ever wondered what challenges are faced by other... Read More

    Ecommerce for Beginners

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

    Web Designer? You Dont Need No Stinkin Web Designer!

    RIVERSIDE, CA August 4, 2004 ?- "Historically, small business owners... Read More

    You Don?t Have to be Amazon.com to Achieve 12% Conversion Rates!

    That's right. According to a recent study by Nielsen/NetRatings, Amazon.com... Read More

    Newsletter Management Using PHP w/o mySQL for Beginners

    Let's begin by setting some limits. If you're like me,... Read More

    Five Reasons You Have to Stop Your Web Site

    That's right. Your method, behavior and strategy you are now... Read More

    Duplication vs. Individualism

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

    Web Coach Tip: What You Should Know About DIY Web Sites

    Recently, a friend asked "What's the deal with those DIY... Read More

    Adding Word Rich Content to Your Website

    You have permission to publish this article electronically, in print,... Read More

    4 Rock Solid Reasons For Building Your Own Website

    What is the point of having a website, you may... Read More

    Stop Losing Precious Web Site Traffic to the Dreaded World Wide Web Black Hole

    You work hard to build traffic to your web page.... Read More

    Five Essential Questions to Answer Before Creating Your First (or second...or third) Website

    Right after the thought, "I need a website," people usually... Read More

    Functions and Subroutines in ASP

    Functions and Subroutines in ASP If you read... Read More

    Getting a Web Site Can Be Fast, Easy, and Inexpensive When You Know Your Options

    So what do you do if need to get a... Read More

    The Road to Better Results

    A lot has changed in the way sites are optimized... Read More

    How One Word Or Even One Letter Can Boost Conversion Rates By Over 400%!

    Recently I was reviewing the keyword specific conversion rate data... Read More

    HTML Editors - How to Choose the Right One for Building Your Websites

    There are lots of HTML editors on the market, however,... Read More

    Get Your Business on the Web

    I can't think of any business alive today that couldn't... Read More

    Do You Need a Web Database?

    Does My Web Site Require A Web Database?If your web... Read More

    Tips to Protect Your Downloads or Products

    1. Upload robots.txt file in to your root directory and... Read More

    5 Essential Traits Of A Home Business Website

    So you've decided to start an online work at home... 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

    What ROI You Should Expect From Your Web Site

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

    Antigo wedding limo ..