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

    quick home cleaning Glenview ..
    In The News:

    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.
    Texas family reunites with missing 11-year-old cat Grayson after 103 days using Petco Love Lost's AI photo matching technology and community help.
    Tired of AI customer service loops? These insider tricks help you escape "frustration AI" and get real human help when you need it most for urgent issues.
    Unlock richer audio from your streaming apps with simple tweaks to volume normalization, equalizer settings, and quality preferences for cleaner sound.
    Scammers are sending fake Facebook settlement payout emails that mimic legitimate notices from the privacy settlement administrator to deceive users.
    Holiday shopping scams surge as fake refund emails target distracted consumers during Black Friday and holiday seasons, costing Americans billions annually.
    The AI-powered IRMO M1 exoskeleton features four modes, including turbo, eco, training and rest for hiking, running, cycling and sports with eight-hour battery life.
    OpenAI announced upgrades for its ChatGPT Images platform on Tuesday, saying the program can now make more precise edits and produce images more quickly.
    Chrome for Android now turns web articles into AI-powered podcast conversations. Get hands-free browsing with Google Gemini's natural audio summaries.
    LastPass faces $1.6 million fine from U.K. regulators after 2022 data breach exposed 1.6 million users. Password manager failed proper security controls.
    Petco disclosed a data breach exposing customer Social Security numbers, financial account details, and driver's license information due to a software error.
    Baseball teams can now analyze complete swing mechanics in normal training environments using Theia's markerless AI system that processes standard high-speed footage.
    Smart home hacking fears overblown? Expert reveals real cybersecurity risks and simple protection tips to keep your connected devices safe from hackers.
    MIT develops needle-free glucose monitor using light technology. Revolutionary device could replace painful finger pricks for diabetes management.
    The ClickFix campaign disguises malware as legitimate Windows updates, using steganography to hide shellcode in PNG files and bypass security detection systems.
    Researchers from Osaka Metropolitan University designed a 21-foot dome that combines aquaculture and hydroponics to create a self-sustaining urban food system.
    The Fox News AI Newsletter gives readers the latest AI technology advancements, covering the challenges and opportunities AI presents.
    ChatGPT data breach exposes personal info of users through partner Mixpanel. OpenAI confirms names, emails compromised in security incident.
    Android rolls out Emergency Live Video for 911 calls, letting dispatchers see real-time scenes during emergencies. Great for holiday travel safety.
    Malicious Chrome and Edge extensions collected browsing history, keystrokes and personal data from millions of users before Google and Microsoft removed them.
    Google's new Call Reason feature lets Android users mark calls as urgent before dialing, displaying an urgent label to recipients using Phone by Google app.

    From Search to Sale

    The Internet car buyer is an elusive animal. Trying to... Read More

    Now You Have a Web Site - Have You Ever Heard of Accessibility?

    An accessible Web site is easily approached, easily understood, and... Read More

    Study Your Sites Performance Via Hit Tracking

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

    Server Side Includes (SSI) with ASP

    Server Side Includes (SSI) with ASP People often... Read More

    How Disabled Users Access The Internet

    In 1995 a new era of accessibility for disabled people... Read More

    Make Your Own Brand!

    There are millions and millions of websites on the Internet.... Read More

    What Works and What not Works for Your Internet Business

    "Build it and they will come."--Filed of Dreams (1989) If... Read More

    How Does Your Website Make Me Feel?

    When people think about the Internet, they think about technology.... Read More

    Content Management ? The New Standard in Web Design

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

    Build or Buy a CMS?

    Creating a content management system either from scratch,... Read More

    Website Strategy!

    A website lets you put your products in front of... Read More

    What YOU Should Know Before Getting A Web Site!

    Everyday thousands of new businesses make the leap and take... Read More

    Achieving Differentiation With Your Website

    Internet Marketing is not a miracle marketing strategy ? competition... Read More

    High Quality Website at Low Cost

    Although designing a great web site is an important part... Read More

    Successful Commercial Sites

    Do you make your website just to entertain yourself or... Read More

    The Cost Of A Web Site

    Just starting out, you can start with a simple informational... Read More

    Five Question-Five Minute Web Makeover Quiz

    If you haven't made the sales and built your clients... Read More

    How to Handle Web Surfers Who Disabled JavaScript

    There are hundreds of millions of Web surfers today. Each... Read More

    Entangled in the World Wide Web

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

    Website Value - Whats Your Business Website Worth?

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

    Creating Dynamic Website Content with PHP - MySQL

    Fresh website content for your visitors can be of real... Read More

    Make Your Web Site Stand Out

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

    Why You Really Need Your Own Web Page In-order To Make Online Business!

    How many Web Sites did you stumble over telling you... Read More

    Tips to Protect Your Downloads or Products

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

    Build a Strong Foundation for Creating Your First Online Identity ? Notes for Beginners

    If you are looking for creating your online presence you... Read More

    scheduled maid service Winnetka ..