Certificated Actions - One Click Only

01/14/2009 Updated CanProcessAction - left out where it creates an ID!

Here's something that comes up periodically, "how do you prevent the dreaded double-click?" From something as common as a banking or purchasing transaction getting run twice or more because of overzealous clicking, to batch processing for the night - to pushing items through workflow. How do you prevent it?

A typical strategy is to disable the button in javascript. This works, somewhat, but doesn't prevent someone from hitting refresh once they get to the next page.

My strategy, certificated submits:

  1. A Table (in MySQL here):
     
    CREATE TABLE CLICK_CERTIFICATES (
      certificate_id varchar(40) not null,
      primary key (certificate_id)
    )
    
  2. A way to create a GUID or unqiue id:
     
    function CreateGUID(){
     srand((double)microtime()*1000000);
     $r = rand ;
     $u = uniqid($r);
     $m = md5 ($u);
     return($m);
    }
    
  3. A function that tells us if we can process the action:
      
    function CanProcessAction($certificate_id){
      $certificate_id = addslashes($certificate_id);
    if(trim($certificate_id)!=""){
      $fetch = mysql_query("select count(*) from CLICK_CERTIFICATES where certificate_id='$certificate_id'");
      $row = mysql_fetch_row($fetch);
      $exists =  ($row[0]!=0);
    } else { $exists = false; $certificate_id=CreateGUID();}
      if(!exists){
        mysql_unbuffered_query("insert into CLICK_CERTIFICATES (certificate_id) values ('$certificate_id')");
      }
      return !$exists;
    } 
    
  4. Now, just use a hidden variable on your form that creates the value of the certificate:
     
    <input type="hidden" name="certificate_id" value="<? echo CreateGUID(); ?>">
    
  5. And then just wrap your action on the receiving page like so:
      
    $certificate_id = $_POST["certificate_id"];
    if (CanProcessAction($certificate_id)){
       //do something only this once, even if they clicked twice, or refreshed the page.
    } 
    

You can also put other things in the table to "re-allow" an attempt after a certain amount of time, or log the extra clicks so you can nag your users. By doing the time control, you can prevent users from re-running resource intensive reports for a given interval, and caching the results.




Cloud Experiments

A recent project I was on was written in Erlang, which I now find extremely interesting as a programming tool. I do, however, have a software business focusing on small and medium sized businesses, which should come as no suprise has very few opportunities to use something like Erlang without a lot of explanations up front.

So, a little here, a little there I started trying to pull out the interesting cloud-like capabilities of that might be useful in other languages... and seeing if I might be able to apply them to some of the tools I currently use. I've come up with two moderately successful prototypes: 1) Distributed Javascript processing and 2) Distributed PHP processing

Javascript

As reviled (and revered) a tool as Javascript is, I believe that Web 2.0 has pretty much cemented Javascript as a language of the future. So, my reasoning says, since computing is moving "into the cloud" (insert random definition) and requires massive parallelization, I believe good old JS could learn a thing or two from Erlang. Spawning processes on a lightweight thread, clouds of machines working together, a message queue per process, a signalling system, copy-on-write (or on call) ... lots of little things that would make Javascript automatically distribute into a cloud.

But is it possible? Yes, Javascript showed me it has one great little feature that I never expected. By referring to a function, you can actually get the source to the call:

 
var X = function(A){ alert(A);}

document.write(X);
X('woo!'); 

Drop this code into a blank html page, and you'll see it call the function X, as well as dump the source. This was an eye opener. I have a working prototype, using PHP as a "marshall" to push code, and accompanying data, out to multiple servers to be processed. This isn't quite the way Erlang does it, but definitely offers a working example that this kind of cloud behavior is possible... so given an array of websites, or numerical data, we can Map and Reduce over an extended cloud - the whole thing being done in JS.

I'm trying to decide whether to open-source the project (It uses Erlang underneath since it handles much of the workload quite nicely) - or if I should try and build a product with it. I'd be open to suggestions or assistance, or partnerships.

PHP

So, I thought, PHP seems like a fairly dynamic language - that would let me get away with similar things. Not quite - BUT, I was able to prototype a "roundrobin" type worker system, using asynchronous socket calls in PHP - literally calling back into the PHP pages to perform the work. PHP can do some dynamic includes, and call_user_func magic as well, giving us a nice way to take an array of data and process on multiple machines, with no special software other than the PHP pages.

This isn't exactly what I want, but it does allow for some extremely parallel processing for PHP. I'd like to scale up the idea and make a series of PHP servers work in tandem as a cloud - but for now I plan on just using it to start running the Wallcloud website again.. hopefully this time without so much of my own interaction.

Anyway, just some thoughts for you to consider. - Mike




Netbooks - ask the network

I have a business client who, since I happen to live and breathe in the computing world, ask me a very simple question: For someone who travels a lot, a huge laptop is just a big pain - what is out there in the world of netbooks? I popped over to Linked-In and figured I'd ask my network - which actually includes a lot more people than I thought.

This opened the floodgates. I thought I'd share some of the results.

My goal here was actually even simpler than some of the replies. Email, Web, and an office suite are really all we're looking for - but I'll post everything I could find.

While I don't any super clear winners, it looks like HP and Dell take the cake for support and compatability, and the Asus, Acer, and MSI Wind products for general appeal. Hope this helps someone looking for hardware

    The results:
  • MSI Wind 2 direct good experience (light, wonderful)
  • Acer Aspire (11.6") 2 people like - easy to upgrade memory and HD, great keyboard , 1 person Acer Inspire "sleek like crazy"
  • Acer 1420P - 1 liked (special edition), great battery life and touch screen look for PDC version on ebay.
  • Asus eee - 2 Heard Good, 2 Liked (900 series and 1005HA), 1 experience Bad connection w/ AT&T built-in, worked with Sprint stick. 1 Worse service than HP
  • ASUS 1000HE - great keyboard,wireless,bluetooth, memory upgrade was easy, Win 7 without problems
  • ASUS 9H - great with XP
  • T91 - 1 Heard Good
  • R1f tablet - 1 Heard Good
  • HP Netbooks - 1 Liked support, 4 liked in general Mini 311-1000NR very nice.
  • Lenovo S10 and S12 (bigger). Cheap, windows, easy upgrade - nice screen and very light.
  • Dell - 2 Liked Support over HP/Asus, 2 liked Driver compatability , 1 liked for price (Vostro A90)
  • Toshiba NB205 - 1 liked and gave up the laptop on trips, long battery life.
    General:
  1. recommend as much ram as possible
  2. Solid state drive if you can afford it
  3. May want to stick with GSM for international travel if can afford.
  4. Avoid using for large app demos, fine for presentations.
    Links:
  1. http://www.squidoo.com/netbook-comparison
  2. http://blogs.techrepublic.com.com/hiner/?p=3360&tag=nl.e101
  3. Top 10 netbooks for 2009 - http://computers.toptenreviews.com/netbooks/



Page :  1