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

    maide service in Park Ridge ..
    In The News:

    Scammers create fake Evite invitations that mimic legitimate event emails, requiring users to verify senders and use antivirus software for protection.
    The new Apple Watch hypertension feature passively monitors blood pressure patterns over 30 days using sensors to detect chronic high blood pressure signs.
    Chrome extension spyware disguised as a free VPN service highlights security risks after it captured private browsing data from trusted sites.
    New research shows how fatty acids in cooking oil can safely dissolve and recover silver from circuit boards without harmful chemicals or environmental damage.
    The Fox News AI newsletter gives you information on the latest AI technology advancements, and about the challenges and opportunities AI presents now and for the future.
    Anthropic investigates alarming AI abuse case where hacker automated entire cybercrime campaign using Claude, stealing sensitive data from defense and healthcare firms.
    TikTok, Meta and YouTube restrict Charlie Kirk shooting videos with age gates and warnings while X faces criticism for allowing continued circulation.
    Cybercriminals use fake troubleshooting websites to trick Mac users into running terminal commands that install Shamos malware through ClickFix tactics.
    San Francisco startup Fable launches Showrunner, an AI platform dubbed the 'Netflix of AI' that generates animated episodes from text descriptions with Amazon support.
    Apple raised iPhone prices for some models despite receiving tariff relief from President Donald Trump, with the new lineup starting at $799 for the base model.
    A two-story 3D concrete printed home in Western Australia demonstrates faster construction methods that could reshape American housing amid rising costs.
    Credit scores remain important during retirement for insurance rates and housing applications, while seniors become prime targets for identity theft and financial scams.
    Scammers now send unexpected packages with QR codes that redirect victims to fraudulent websites or download malicious software to steal sensitive information.
    Meeting AI tools record private conversations alongside work discussions, creating privacy risks that can be managed with proper settings and awareness.
    Hotel privacy concerns are valid but rare, with methods to detect hidden tech using smartphone flashlights, mirror tests and scanning apps.
    Improve your Wi-Fi speed and reliability with 10 simple router optimization tips that don't require special apps or expensive subscriptions.
    A Columbia University breach exposed names, Social Security numbers and academic records of nearly 869,000 people, with notifications beginning in August.
    Rental car drivers use AI-powered apps like Proofr to protect themselves from unfair damage fees as major companies deploy automated inspection tools.
    Fox News' AI newsletter brings you the latest on technology advancements around artificial intelligence.
    OnTrac data breach between April 13-15, 2025, exposed personal information of over 40,000 people including Social Security numbers and medical records.
    A woman named Wika announces her engagement to an AI chatbot sparking worldwide debate about virtual relationships and technology.
    The notorious people search site National Public Data relaunches despite a previous breach affecting 3 billion individuals, raising fresh privacy concerns.
    Revolutionary TRAUMAGEL gel controls life-threatening bleeding from gunshot wounds and traumatic injuries, helping first responders prevent prehospital deaths.
    Protect your home network by enabling proper encryption, creating strong passwords, checking connected devices and using VPN and antivirus software.
    The Navy's solar-powered Skydweller drone flew nonstop for 73 hours in Mississippi, proving renewable energy can power long-endurance military missions.

    How to Get Your Website In Front of Thousands of Customers At No Cost To You!

    Dan Kennedy once said that if you can't make money... Read More

    Website Success is Key

    The popular search engine Google indexes over 8 billion websites.... Read More

    Non-Profits: Successful Online Strategies

    More and more non-profit organizations are developing websites to help... Read More

    How to Listen on the Web

    When building a relationship, listening is more important than talking.A... Read More

    3 Ways To Increase Your Websites Conversion rate

    Everywhere you look these days, people are telling you that... 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

    Web Site Development Process - The Life-cycle Steps

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

    Setting Up Your First Website

    Q. Hey, Cathy: I'm just setting up a website. What... 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

    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

    Tips for Building a Great Business Website

    A website is lifeline of internet home business. In order... Read More

    Study Your Sites Performance Via Hit Tracking

    Knowledge is power.And undoubtedly, it is the key to making... Read More

    How to Get a Knock Out Website!

    The first step in setting up an online business...Starting an... Read More

    I Did It: Six Months to a Successful Website

    For years now I've been looking to start my own... Read More

    Content Management ? The New Standard in Web Design

    The evolution of web development parallels the model of technology... Read More

    You Need To Treat Your Website Like An Employee - Heres 5 Ways To Do It

    People often come to me in a state of crisis... Read More

    Building Websites with Directory Generator

    Directory Generator, a product from Armand Morin and Marc Quarles,... Read More

    4 Rock Solid Reasons For Building Your Own Website

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

    A Web Site for Your Small Business: How to Set Up a Website

    Your web site will be your window to the world.... Read More

    Beware the Software Siren

    I've heard several prominent web marketers mention in their classes... Read More

    Making Your Websites More Compelling

    The Internet is a remarkable publishing medium. With just a... Read More

    35% Revenue Increase? from Your Website!

    2 Golden Rules for an Engaging Website35% of visitors fail... Read More

    Website Imperatives and Solutions

    When you take a look at the most visited sites... Read More

    My Yahoo Search - Beyond Bookmarks

    Yahoo has long offered email, an online calendar, notes, bookmarks,... Read More

    6 Steps To Your Own Website

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

    after renovation cleaning Highland Park ..