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

    car service from Midway Burlington .. Lockport Chicago limo O’Hare
    In The News:

    Tech expert Kurt “CyberGuy" Knutsson says a malware app called SpyLend is posing as a financial tool, hitting 100,000-plus downloads.
    Tech expert Kurt “CyberGuy" Knutsson says Clone Robotics’ Protoclone mimics humans with 1,000 muscles – too human for comfort.
    Tech expert Kurt “CyberGuy" Knutsson urges you to use Apple’s App Privacy Report to see what your apps are really up to.
    Tech expert Kurt “CyberGuy" Knutsson talks about how to smoothly transfer your data from an old laptop to a new one using cloud storage or external drives.
    Kurt the CyberGuy offers tips to safeguard your personal information as scammers become more sophisticated with scam texts and other methods.
    WeRide's unmanned electric delivery van, the Robovan W5, has 194 cubic feet of cargo space and can carry payloads up to about 2,205 pounds
    Kurt the CyberGuy recommends deleting 16 browser extensions immediately in response to a report saying more than 3.2 million web users were affected by a security breach.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    A robotics firm in China claims a robot has performed the world's first humanoid robot front flip, which is significantly more difficult than a backflip.
    A digital ID may be even more secure than a physical ID. Storing your driver's license in your Apple Wallet is an ideal solution for commuters.
    A cybersecurity firm has shed some light on just how common tax scams have become. Kurt the CyberGuy offers his advice for how to protect your refund.
    Lifesize Plans offers immersive walk-throughs that allow customers the opportunity to tour a home's design before construction actually begins.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    A man invested $4 million in bitcoin and lost it all with a single click when he was targeted by a vishing scam, which uses phone calls to trick people.
    Expandable's Touchdown is a designer trailer that promises a luxury off-grid living experience and unfolds into a home in about 15 minutes.
    Major employee screening company data breach affects 3.3 million people. Tech expert Kurt “CyberGuy" Knutsson explains what happened and gives five ways to protect your data.
    Kurt “CyberGuy" Knutsson reveals mind-blowing tech that gives you sunlight on demand.
    New malware "FrigidStealer" targets Mac computers. Tech expert Kurt “CyberGuy" Knutsson offers four ways to stay safe from infostealer malware.
    Kurt “CyberGuy" Knutsson talks about how lab-grown muscles power a biohybrid hand for scalable prosthetics and research.
    Reports of task scams have significantly risen in the past four years, according to the Federal Trade Commission. Kurt the CyberGuy offers some red flags.
    iPhones have a hidden folder that eats up storage without you knowing it. Kurt the CyberGuy offers some tricks to free up storage on your device.
    A recent ransomeware attack targeted Zacks, an American investment firm, and a cybercriminal claimed to have stolen records for millions of customers.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    Researchers unveiled a new soft prosthetic hand that combines the natural coordination patterns of our fingers with the decoding of motoneuron activity in the spinal column.
    Accidentally deleting a text message on your iPhone or iPad is not a problem if you still need the message. Apple has a built-in way to recover it.

    Conceptualize, Build and Publish a Web site

    Conceptualize, Build and Publish a Web site - What's required... Read More

    Setting Up Your First Website

    Q. Hey, Cathy: I'm just setting up a website. What... Read More

    Art, Artists, and the Web:Part: 2--First Steps in Building an Artist?s Website

    What you should do and know if you are an... Read More

    Pick Up Your Own Domain Name

    Think up a name and check if yourname.com is available.... Read More

    A Website Is Not Enough

    Your ObjectiveYour small business needs an appealing and professional website... Read More

    How to Create a Professional Web Site in 24 Hours

    While creating a Web site may seem like... Read More

    The Birth of a Professional Web Site

    The Internet has opened a whole New World of opportunity... Read More

    Give Your Business a Cash Infusion

    Whether you have your own business already, or are looking... Read More

    10 Simple Steps: Its Magic If You can E-Mail You can Update Your Web Page Dynamically

    Dynamically Update Your Web Pages Via E-MailIf you can Send... Read More

    Using Mini Websites - Powerful Way to Direct Marketing

    Mini Websites are the most powerful and cost effective solution... Read More

    Lead Generation How to -- 10 Tips On Generating More Internet Sales Leads

    Many millions of dollars are being wasted on promoting and... Read More

    Do Dancers Need A Website?

    Dance is how you pamper your soul and satiate your... Read More

    Marketing Your Business Online

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

    Is Your Web Site Talking to Your Customer?

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

    Easy Steps To Website Development and Promotion

    One of the most important parts of establishing a new... Read More

    Create Huge Income From Your Web Site - 10 Easy Ways

    The cost of setting up a web site is dirt... Read More

    Top 7 Reasons Why Your Business Needs a Website

    A website provides invaluable advantages for businesses who have one.7... Read More

    Entangled in the World Wide Web

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

    7 Reasons YOU Need a Website

    1) A marketing necessityI still hear it said from time... Read More

    Web Development Processes and Technical Environments

    The process of Web application development is critical to the... Read More

    How To Make Your Website More Successful? (Part I)

    Building a website and getting it online is easy. Driving... Read More

    7 Golden Rules For Building Mini Sites

    First, an eye opener. Making your fortune through affiliate programs... Read More

    Tell me what your website does!

    You know exactly what your organisation does and what your... 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

    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

    Granger limo Chicago ..