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

    no-contract cleaning service Des Plaines ..
    In The News:

    Phishing scammers use rnicrosoft.com domain to impersonate Microsoft by replacing "m" with "rn" in typosquatting attacks that steal login credentials.
    OpenAI announces new teen safety rules for ChatGPT users under 18, blocking romantic roleplay and requiring extra caution on body image topics.
    A 2025 data breach at fintech company 700Credit exposes personal information of more than 5.8 million people through compromised third-party integration partner.
    Retailers lose $76.5 billion annually to return fraud as nearly 10% of U.S. retail returns involve fraudulent activity, with $850 billion in returns expected in 2025.
    ShinyHunters claims responsibility for stealing 94GB of Pornhub user data affecting over 200 million records and demands Bitcoin ransom.
    ChatGPT 2025 now connects to Apple Music, Canva, Expedia, TripAdvisor and OpenTable through built-in apps that help users create playlists, design graphics and more.
    Apple releases emergency patches for two zero-day vulnerabilities actively exploited in attacks. iPhone and iPad users urged to update immediately.
    DoorDash launches Zesty, an AI-powered social app that recommends restaurants through conversational search, now testing in San Francisco and New York.
    Cybersecurity firm Infoblox reveals that over 90 percent of parked domains now redirect visitors to scams and malware, making simple typos extremely dangerous.
    The Fox News AI Newsletter covers the latest artificial intelligence technology advancements, including the challenges and opportunities AI presents now and for the future.
    GPT-5.2 is now live for all ChatGPT users with improved coding, writing and image interpretation, with Kurt Knutsson offering his review.
    New iPhone replacement scam uses pressure tactics and fake carrier calls to steal devices from buyers. Criminals claim shipping errors and demand urgent returns.
    Amazon Ring's new facial recognition feature sparks privacy controversy as Electronic Frontier Foundation critics argue the AI upgrade expands surveillance risks.
    New Android banking trojan Sturnus steals credentials, reads encrypted messages and controls devices.
    Denmark's 3D-printed student village proves automation builds 36 apartments faster than traditional methods. Skovsporet project shows housing future.
    Discover Android's new Sound Notifications feature that alerts you to smoke alarms, doorbells, and baby cries even when wearing headphones.
    New SantaStealer malware reportedly threatens holiday shoppers with password theft. This Christmas-themed info-stealer targets browsers and crypto wallets.
    The Christmas season brings a surge in Netflix phishing scams targeting shoppers with fake emails. Stacey P received convincing scam but verified account first.
    San Francisco Giants invite Jamie Grohsong to throw ceremonial first pitch at Oracle Park after he learned to play baseball with a bionic hand following an injury.
    FBI warns cybercriminals are stealing family photos from social media to create fake proof of life images in virtual kidnapping scams targeting victims.
    Instagram's new 'Your Algorithm' tool lets you control your Reels feed in real time. The app now gives you power to customize what videos you see.
    Major Marquis fintech breach exposes 400,000-plus Americans' data through unpatched SonicWall vulnerability, with Texas hardest hit at 354,000 affected.
    Free up iPhone storage fast by clearing large photos and videos from Messages app. Simple steps for iOS users to delete attachments without losing chats.
    Scammers are flooding inboxes with fake tracking alerts that mimic real carriers, exploiting the holiday rush to steal logins and personal data.
    The Fox News AI Newsletter brings you the latest news on AI technology advancements and the challenges and opportunities AI presents now and for the future.

    How To Get Profits From Your 404 Page Not Found File

    "'Page Not Found' on this Server. Check the URL and... Read More

    Creating Compelling Content , Write It and They Will Come

    In a previous ezinearticles.com article,"I Need real visitors, Not Search... Read More

    Free Webmaster Tools - 7 Things Every Webmaster Needs in Their Toolbox

    Webmaster tools are vital to becoming both efficient and effective... Read More

    Get a Website!, Register Your Domain!: To Website or Not to Website?

    If you're fairly new to the Internet scene, you may... Read More

    Why Is No-one Buying From My Website?

    Are you, like many other website owners, frustrated at the... Read More

    Content Management

    More and more businesses are recognizing the importance of content... Read More

    Marketing Your Business Online

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

    Making the Most of Your Website: Start with the Basics

    One of my most salient memories from when I sold... Read More

    Launch Your Own Website Today - Its Easier Than You Think!

    Thousands of people are now making a living online and... Read More

    Is Your Website Doomed for Failure Before Youve Built It?

    One of the things that many people overlook when building... Read More

    Why A Simple Counter is Never Enough for Your Website

    A simple website stats counter is not enough if you... Read More

    Developing A Website: 10 Tips For Getting Started

    1. Be clear on your purpose.Building a website can be... Read More

    3 Ways To Increase Your Websites Conversion rate

    Everywhere you look these days, people are telling you that... Read More

    Instant Relevant Web Site Content - No Its Not a Bot

    In about the Time it takes to Watch a Reality... Read More

    Art, Artists and the Web: Part 4--What to Do After a Website is Designed

    What to do if you are an artist after you... Read More

    Ten Major Tips to Develop a Multilingual Web Site to Work

    If you are living in a country that its native... Read More

    New Years Resolutions: Is Improving Your Website One of Them?

    With the New Year upon us yet again, it's time... Read More

    Flash Deadly Sins (That Can Kill Your Web Business)

    Looks like every client wants a Flash site these days... Read More

    4 Marketing Tips for Resourceful Webmasters!

    The internet is a sea of knowledge. Getting your information... Read More

    PHP & Account Activation

    When a user signs up at your website, you may... Read More

    Top 7 Reasons Why Your Business Needs a Website

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

    Increase Hits to Help Increase Your Business

    In this day and age most businesses consider having their... Read More

    The Web: Your Window of Opportunity

    Thinking about starting up a business? The web is the... Read More

    12 Essential Tips to a Professional Business Website

    1. Choose a big enough font size. A size 12... Read More

    Ten Quick Tests To Check Your Website For Accessibility

    The Disability Discrimination Act says that websites must be made... Read More

    bathroom cleaning service Lake Forest ..