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

    Alexis limo rentals ..
    In The News:

    A Google DeepMind team has developed an artificial intelligence system that can play video games like a human and take native language commands from players.
    Four of the largest school boards in Ontario, Canada have launched lawsuits against TikTok, Meta, and Snapchat, claiming that they have impacted students' thinking and behavior.
    Finalists for the inaugural Women’s Prize for Nonfiction, aimed at addressing the gender imbalance in nonfiction publishing, were unveiled on Wednesday.
    Tech guru Kurt "CyberGuy" Knutsson breaks down whether the government is watching citizens and what they can do to protect online privacy.
    A benchmarking group for artificial intelligence has released new results evaluating the speed of hardware in running AI applications and responding to users.
    Sierra Space’s Dream Chaser spaceplane provides a glimpse into the future of space travel. Traveling to space may become a part of everyday life.
    The new European Hyperloop Center in the Netherlands aims bring in a new era of transportation. The center will use a steel tube as a proving ground for testing the new vehicle.
    Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
    While it may be incredibly tempting to have a “go with the flow" mindset like the rest of your vacation, your technology definitely should not be compromised while traveling.
    Have you ever accidentally deleted an app from your iPhone that you’ve already paid for? Don't worry. We’ve got a trick that will help you get it back without having to buy it again.
    Apple's new Journal app has raised privacy concerns among Apple's userbase. Tech expert Kim Komando examines social media rumors and explains what steps to take to protect yourself.
    Although Facebook has denied that our phones listen to us, they do have other ways of finding out what we are talking about, listening to and searching for.
    With the integration of OpenAI technology, Figure 01 has taken a significant leap forward, showcasing the potential of robots to understand and interact with us on a personal level.
    Port Ellen, newly reopened whisky distillery in Scotland, is using SmokeDNAi technology to understand mouth-feel and flavors during the whisky maturation process.
    Telly, a smart TV firm, is promising to give out their 4K 55-inch TV for free. What must you give in return? The innovative, yet potentially unsettling, answer might shock you.
    The moment a spam invite hits your calendar, it’s like an uninvited guest at a party. So, what do you do? Show it the door.
    Identity thieves are now targeting children and are making large sums of money by exploiting children's identities, possibly hurting their financial future.
    There's a clever way to change the notification sounds on your Android without having to look at your screen. Kurt "CyberGuy" Knutsson explains.
    If your bank accounted has been hacked, there are a number of steps you can take to prevent it from happening again. Kurt "CyberGuy" Knutsson 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.
    The Wave House, a data center in Heidelberg, Germany, is the the largest 3D-printed building in Europe. Its walls were built in about 140 hours.
    Some government agencies around the world are struggling to meet their staffing goals when it comes to hiring artificial intelligence experts.
    Google Maps' recent upgrades have introduced real-time ETA and turn-by-turn directions to your phone's lock screen while you are traveling.
    Kat Cammack says AI could disrupt the 2024 election. A report says shared AI image tools generate election disinformation in 41% of cases and voting disinformation in 59% of cases.
    Deepfakes have become commonplace, and the technology is only getting better, but there are certain elements that might give away the fact that an image is AI-generated.

    Setting Up Your First Website

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

    Credibility - 10 Ways to Build it on Your Website

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

    7 Questions to Understand Your Customer Better

    Customer service questionnaires can help your clients better understand their... Read More

    The Number 1 Reason Most Websites Fail

    Failure, just like success, is measured differently by each and... Read More

    Disability Discrimination Act (DDA) & Web Accessibility

    There's been widespread speculation about the new legislation being introduced... Read More

    How To Get Profits From Your 404 Page Not Found File

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

    Five Question-Five Minute Web Makeover Quiz

    If you haven't made the sales and built your clients... 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

    50 Ways To Use Your Website

    A website is the most versatile and cost-effective marketing tool... Read More

    Beware the Software Siren

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

    Creating Websites that Cater to Exam Preparations

    One of the things that Internet excels is disseminating information... Read More

    PIM Team Case Study: Creating Text Effects With PHP and GD

    See how you can create graphic effects on text with... Read More

    The 2 Most Common Web Site Mistakes

    When we review the sites of potential clients, there are... Read More

    Web Development Processes and Technical Environments

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

    12 Essential Tips to a Professional Business Website

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

    2 Key Ways to Make Your Site a Success

    If one more business owner tells me their website sucks... Read More

    Are Web Graphics Stealing Your Money?

    They might not be wearing a mask and carrying a... Read More

    10 Tips For A Successful Website

    Have you ever thought the secret behind the success of... 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

    Creating Dynamic Website Content with PHP - MySQL

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

    Duplication vs. Individualism

    How can we add Word Rich Content to our Websites... Read More

    5 Tips For A Better Website

    Having an eye catching website is great, but are you... Read More

    5 Tips To Supercharge Your Website Sales Copy

    The art of turning website visitors into paying customers depends... Read More

    Ecommerce for Beginners

    Like most average persons, I wanted some extra money to... Read More

    How To Start Your Own Website

    I'm one of those people that always wanted a website,... Read More

    car service from Midway Alsip ..