views:

971

answers:

2

After reading this on the question How do I uniquely identify computers visiting my web site? :

A possibility is using flash cookies:

Ubiquitous availability (95 percent of visitors will probably have

flash)

You can store more data per cookie (up to 100 KB)

Shared across browsers, so more likely to uniquely identify a machine

Clearing the browser cookies does not remove the flash cookies.

You'll need to build a small (hidden) flash movie to read and write them.

I tried to find if someone has already done something like this, so I wouldn´t have to reinvent the wheel. So far, no luck(maybe I don´t know the right term to search), except for the code in the flash side

The use I have for this is to prevent a user to answer a quiz multiple times, but future uses maybe banning trolls.

Does anyone knows a open source library that does this and allows me to access via javascript?

Caveats: I don't know flash and I don't own a license.

+1  A: 

I'm hesitant to answer your question, because it sounds like this is straying dangerously close to Evil... Also, it's doomed to failure. If you really want to prevent a user from answering a quiz multiple times, the best thing you can do is have them register a user account. If you want to prevent them from registering multiple user accounts, you can have them verify something through a credit card or snail mail, both of which are generally untenable solutions. In short, the internet is anonymous.

Anyways, if you really want to go forward with this plan, you can build your application in Flex (a variant of Flash) fairly trivially. There's tons of documentation on the Adobe site. Some of it is rather sparse and annoying, particularly the collections API, but it'll be sufficient for your purposes. ActionScript (the programming language underlying both Flash and Flex) is very much like JavaScript and easy to learn. Flex has a free SDK (usually available in a small link from the page that tells you to get the expensive Flex Builder; Flex Builder is a primarily GUI tool, whereas you'll be writing straight code without an IDE with just the SDK), so a license shouldn't be a problem. The JavaScript to Flash bridge is also well documented.

rmeador
Thanks rmeador, I'll take a look in Flex. =)
Tiago
+1  A: 

To build on what rmeador said, and to help get you started, you are going to need to know how to use two classes in the FLEX3 API, SharedObject and ExternalInterface.

SharedObject will allow you to store and retrive data from a client computer and ExternalInterface will allow your actionscript to communicate with your javascript.

Using shared object is simple.

To put data onto a users machine just create a SharedObject and add properities to the sharedObject's data properity.

  private var sharedObject : SharedObject = SharedObject.getLocal("myCookie");
  sharedObject.data.DATA_FOR_THE_COOKIE = DATA;

Retriving data from the SharedObject is just as simple. Make sure the size of the SharedObject is greater than 0 (Make sure the SharedObject exists) and the just look up the properity names through the SharedObject's data properity.

if(sharedObject.size > 0)
       // access data from cookie with -> sharedObject.data.DATA_FROM_THE_COOKIE;

To pass the data stored in the SharedObject to your javascript you are going to need to use ExternalInterface.

Lets say you have a javascript function to retrieve the variables

function retrieveVars( vars ){
   // Do something with vars.
}

To call this function from actionscript you will use

ExternalInterface.call("retrieveVars", DATA_ITEM_1, DATA_ITEM_2, ...);

Its that simple.

Please note that this technique will not work if the client's flash player has its storage settings set at 0, or if the client's browser does not have ActiveX or NPRuntime.

ForYourOwnGood
Thanks for the explanation!
Tiago