Web Development

Web Development - Articles & Information To Help You With Web Development

Preventing Repeat Form Submission Using Php Sessions


Web Development

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
    See here for more detailed information, an example using PHP, and an alternate method which doesn't require sessions.







    Created & Maintained by Empower! CMS Web Sites

    Host2Sell Web Hosting   |   Emarketing Workshops   |   Site SEO Review   |   FREE Newsletter

    South Africa's Top Sites




    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |











    Website Sales: 10 Reasons Why People Dont Buy From You
    You've put up a website to promote a product orservice.You've spent piles of cash to generate traffic.But sales are not coming in.So, you're wondering what is wrong?Here are 10 website sales secret reasons why theyare not buying from you:1. You don't make people feel safe when they order.Remind people that they are ordering through a secureserver. Tell them you won't sell their e-mail addressand all their information will be kept confidential.2. You don't make your ad copy attractive. Your adlists features instead of benefits. The...(related: Web Development)


    Developing A Website: 10 Tips For Getting Started
    1. Be clear on your purpose.Building a website can be a long and arduous procedure if you are not sure what you are doing. However, if you have a clear focus as to what you expect your website to do for your business/organization, things will flow much more smoothly. The purpose can be anything from selling widgets online to keeping members of your soccer team updated. Regardless, f...(related: Web Development)


    9 Simple Steps To Create A Background Tiled Image Branded With Your Name
    You have seen those web pages where they have the name of the Name Web repeated over over over in square tiles as the background. Now by following these 9 Simple steps you too can create a web page Branded with your Name, or Company Name.I am far from a graphic designer but by using Microsoft Word and Microsoft Paint and these 9 Simple Steps. I have been able to create Tiled background Images.Step 1Go into Microsoft Word and Create a Word Art with your Text.
    • Click on Menu Item Insert then Picture Then Word Art.
    • Select a Word Art Template
    • Enter Your Word art Text
    • Select your Font Style and Size
    • Rotate your Word Art (Going from Top Right to Bottom Left seems to work best)
    Step 2Open Paint...(related: Web Development)


    How Did You Get Here?
    When marketing your website, it's important to know which of your efforts are producing results and which of them are a waste of time.You can learn a lot about this by analyzing your website's statistics (as...(related: Web Development)


    Website Imperatives And Solutions
    When you take a look at the most visited sites on the internet, what hits you in the face? Change, growth, new content. In a sense, a search engine is the perfect web site. By it's very nature, it grows and changes continuously and moment by moment adds new content. But, most of us are never going to build a Yahoo or a Google. The competition at that level is horrific.But the lesson is there to be r...(related: Web Development)


    Is Your Web Site Talking To Your Customer?
    A while ago one of my clients approached me and mentioned thatthey were experiencing a serious problem with customerregistrations (obtaining customer names and e-mail addresses),on their web si...(related: Web Development)


    The Problem With Paypal On Your Web Page
    When I set up my website I felt paypal was a very simple and easy solution when people wished to purchase my products.For 6 months I was getting 150-200 unique visitor...(related: Web Development)


    Functions And Subroutines In Asp

    Functions and Subroutines in ASP

    If you read our Tutorial on Include Files (SSI) then you learned how to encapsulate ASP code within include files and the benefits it brings us.

    As developers, we should endeavour to make our lives easier wherever possible... no one wants to re-invent the wheel after all.

    Functions and Subroutines exist to not only save us time, but to bring power to our ASP.

    They are just another way of encapsulating code, but have a lot more functionality than just 'saving some code for later'.

    First, let's look at Functions... Imagine a ballo...(related: Web Development)


    Planning Your Website For Success
    Most people know they need a website in order to publicise and promote their business but very few people know what they want in their website. Fewer still are those who can actually sit down and plan their websites well.If you don't plan ahead, problems will crop up later.For example, who is going to take care of the website? What are the costs involved? Will you have the time to maintain it or should you hire a webmaster?T...(related: Web Development)


    So You Want To Have A Website
    So you want to have a website. You have gone on to the internet and surfed but you have no idea what developing a website involves.You are not aloneThe majority of my clients know they need a website but they feel overwhelmed and intimidated by internet technology and why not? Internet technology is continually evolving and changing. What is true this month may not be true next month.



    Google




    Bring Your Visitors Back Clamoring For More! Maintain And Improve Your Web Site Weekly - Part 1
    80% of your Web site is Maintenance!Once your Web site is up, you must maintain it. That means changes, and each time you make a change, you may make a mistake. I'm really grateful when people point out myWeb glitches by emailing me, and these encourage me to be more proactive by checking my site each week.If your visitors get a link that doesn't work, see incomplete instructions, or read your dull instead of passionate copy, they will leave your site immediately, and not bookmark it.Before you invite potential buyers to see your masterpiece you need to check and correct all parts of your site, and especially the home page. Use the seven tests below to guarantee you loyal customers and clients.1. TEST YOU...(related: Web Development)

    Where?s Your Web Site?
    This simple question can take on several different forms, but if you have your own web site, all are equally important. Don't worry, this isn't a sales letter, and it's well worth a read.That opening question can mean "where is your web site hosted?", or "where in the search engines is your web site?", or it can mean "where in your marketing does it appear?"Let's take the first option. Do you actually know where your web site is held? To most people, it's not really that important, as long as you receive the service you require. The problem comes when you don't really know what's available. Get your current web site provider to tell you exactly what you are getting, and how much you are paying for each component of it, and then compare it with other companies. This is a very competitive...(related: Web Development)

    Let Marketing Manage Your Website Content
    The definition of the phrase "Content Management" depends on what the organization may need or a vendor may offer. There is no general purpose or standard content management system that can satisfy today's diverse business needs across the board. And so, factors for successfully implementing a content management system vary depending on individual business needs.Conducting a thorough assessment of an organization's specific business application or processes prior to installation is one of the keys to implementing a successful content management system. T...(related: Web Development)

    site-map - Copyright © 2006 Empower! Web Design | All Rights Reserved. | Web Development