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

    limousine Ackley .. Lockport Chicago limo O’Hare
    In The News:

    A virtual private network can help ensure your information remains security and your privacy remains intact. Kurt the CyberGuy explains.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Artificial intelligence-based cameras are giving air defense operators unprecedented capabilities in monitoring and protecting airspace.
    Apple's iOS 18.1 Inactivity Reboot automatically reboots your iPhone if it hasn't been used or unlocked for more than three days, providing better data protection.
    An inventor designed rooftop solar panels for a Tesla that draws solar energy while the car is parked, adding travel mileage without plugging in.
    There are currently no laws governing what artificial intelligence can and cannot do with the information it gathers; here are 10 things to avoid telling AI chatbots to keep yourself safe.
    A credit union with over 240,000 members recently revealed it was targeted by cybercriminals, resulting in a data breach that was part of a two-month attack by hackers.
    Scammers have become skilled at creating convincing fake websites that can easily fool unsuspecting users. The CyberGuy offers tips to protect yourself.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    CAPTCHAs, which are used by websites to confirm whether users are people or bots, are harmless, but hackers are using them to infect PCs with malware.
    Hackers recently leaked personal information of about 500,000 Americans and stole patient medical records that included lab results and insurance details.
    The holiday season sees a rise in mobile shopping scams. Tech expert Kurt “CyberGuy" Knutsson helps you learn how to stay safe.
    Tech expert Kurt “CyberGuy" Knutsson says a VPN enhances online banking security by encrypting data and protecting privacy.
    Beware of these six sneaky holiday scams. Tech expert Kurt “CyberGuy" Knutsson gives you tips to avoid falling victim.
    Tech expert Kurt “CyberGuy" Knutsson reveals how to securely back up and factory reset your Android to protect your privacy and data.
    Artificial intelligence is making life easier for cybercriminals, allowing them to create elaborate scams to trick people. Kurt the Cyberguy explains how to protect yourself.
    Cut through all the digital clutter and delete multiple emails from your Android simultaneously. Kurt the CyberGuy explains how it's done.
    Tips to prevent your holiday decorations from being stolen
    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 lays out the immediate steps you should take if your phone has been hacked and your personal information becomes vulnerable.
    Fraudsters are sending people bogus invoices through PayPal as part of a sneaky scam that is going around; here's how to protect yourself from being fooled.
    A former Colgate-Palmolive employee was shocked to discover $750,000 had been drained from her 401(k) account. "CyberGuy" offers tips on how to prevent identity theft.
    Electric vehicle maker Harbinger recently showed its electric delivery truck can handle icy roads with agility and stability in winter.
    To make the busiest time of year more manageable, here are some tricks for tracking your packages, taking quality family photos and curating the perfect Christmas playlist.
    Kurt "CyberGuy" Knutsson explains how to keep your online Amazon gift purchases a secret from loved ones or friends this holiday season.

    Improve Conversion Rates ? Effective Content

    Your site is fast and getting traffic, but conversion rates... Read More

    Earning From Your Website

    Before you start building your site, ask yourself "WHY?". Why... Read More

    Your Biggest Mistake When You Create a Website?

    --------------------------------Why Should You Create a website?--------------------------------A. What do you want... Read More

    Web Site Development Process - The Life-cycle Steps

    A system development process can follow a number of standard... Read More

    Your Future Profit Is In The Stars

    You don't believe in astrology but you check your horoscope... Read More

    FREE Amber Alert Tickers for Your Website

    Project Safekids provides webmasters a valuable tool which could save... 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

    Web Designer? You Dont Need No Stinkin Web Designer!

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

    Website Value - Whats Your Business Website Worth?

    If you were asked to put a value on your... Read More

    Making The Business Case For Web Standards

    Through the explosive growth of the Web, companies have realized... Read More

    Why Local Service Companies Should Have a Website

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

    Direct Sales and Your Corporate Website - A Creative Marketing Plan that Works!

    Creatively marketing your corporate site takes time in the set... Read More

    Having a Domain Name And Web Site Gives Your Business The Key To The Door

    Just like all things in life, the ways to run... Read More

    Preventing Repeat Form Submission Using PHP Sessions

    We've all seen those messages on some websites warning not... Read More

    Make Your Communication Come Alive

    Design and layout can make your communication come alive and... Read More

    Thinking Of Taking Money Online? Whats Best For Merchants? PayPal, WorldPay or Something Else?

    It's now easier than ever to take payments on the... Read More

    Successful Web Development: 10 Key Elements

    There are many elements that are key to successful web... Read More

    Email Addresses in Web Pages

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

    Make Your Web Site Stand Out

    When visitors add your web site to their Favorites or... Read More

    Trust Us! Sending Credible Messages

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

    Credibility - 10 Ways to Build it on Your Website

    If you have your own business website and you are... Read More

    The 5 Biggest Mistakes Almost All Web Designers Make

    Huge Mistake #1: Creating a Website with Flash -- Did... Read More

    5 Essential Traits Of A Home Business Website

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

    CPanel Fantastico - Features and Benefits

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

    Why a CSS Website Layout Will Make You Money

    Although CSS layouts have been around for years, they haven't... Read More

    shuttle from O'Hare Alexander ..