简体   繁体   中英

Read and process data from a flash cookie

I want to create a flash swf file that will store a token in Local Shared Object. What do I need to do to read that token and look it up in the database on the back end? Is this possible at all?

here is a possible scenario:

  1. User visits my web page
  2. A token is generated on the server and stored in the database
  3. Token is then saved in LSO
  4. User leaves the site (maybe shuts down his computer) and comes back later
  5. Token is read, located in the database and the user is recognized (lets say that token is a foreign key that links to other user data stored in the db)

I researched this for quite a while and all I find is that flash can use LSO to store read data for flash movie... Does this mean that the data can not be accessed by the server?

Thank you!

Yes, it's possible but you need to see it as two different operations. On one hand you store & read a SharedObject, on the other hand you communicate with the server and query a database.

You could use ZendAmf server to communicate with PHP. You would be able to send the SharedObject data to PHP in order to make the database query, when the database returns a result , ZendAmf sends a response to Flash.

Check this Zend Amf video introduction by Lee Brimelow

I partly agree with PatrickS; the functionality you desire should be thought of as a set of distinct processes. But I think the size of that set is 3, not 2:

  1. A process capable of inserting and retrieving data in a database
  2. A process capable of transmitting data between a client and a server
  3. A process capable of inserting and retrieving data in a LSO

So no, LSO data cannot be created or accessed by the server. It can, however, be created or accessed (and sent back) on behalf of the server. And that is best done with the use of ExternalInterface , like so:

  1. Encapsulate in a method, the Actionscript code which handles the LSO data.
  2. Register the method with the external interface of the prospective Flash application it is defined in using ExternalInterface.addCallback() .
  3. Compile the Flash application, and create an element in your HTML that references the resultant .swf file.
  4. Create a DOMElement representation of the HTML element, and call the method in #1, which should now be defined as a member of the DOMElement .

Check out BakedGoods if you don't want to go through the trouble of doing all of this; its a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities, including Flash Locally Shared Objects.

With it, creating an LSO can be accomplished with code as simple as:

bakedGoods.set({
    data: [{key: "key", value: "value"}],
    storageTypes: ["flash"],
    complete: function(byStorageTypeRemovedItemKeysObj, byStorageTypeErrorObj){/*code*/}
});

Retrieving and removing data is just as easy. Trust me on all of this, I would know; i'm its maintainer :)

Since you have tagged the question with asp.net, I believe storing/retrieving/validating a cookie would not be the problem for you.

Otherwise too, If you need help working with cookies in asp.net.....the net is full of those how to's. One to save your strokes : http://msdn.microsoft.com/en-us/library/ms178194.aspx

So if data like passwords, User details, etc is not what your " token " refers to, then all you need is to pass the token as a sort of query string. This can be done using flashvars.

Visit the link for a good little tute up.

http://www.permadi.com/tutorial/flashVars/index.html


Edit

I was merely pointing out that asp does it way elegantly.

Use the token , read from the LSO to remember the user.

var token:SharedObject;
token = SharedObject.getLocal("UserToken");

if (token.data.value==undefined)
    token.data.value = ?; // Pass the User token here while writing
else            
    ? = token.data.value; // Use the values while reading

If you wish to work with a Local shared object example, follow this: http://www.emanueleferonato.com/2008/12/28/understanding-as3-shared-objects/

But please do remember storing things without users knowledge is not advisable. So do take pains to let the user know that he will be remembered by the website. Something like remember me checkbox?

Local Shared Objects are more like local storage than like cookies. The term "Flash cookie" is kind of suitable from an end user perspective, but technically, a LSO is not like a cookie, it is not sent along automatically in HTTP requests. Instead, code on the client needs to read the value from the LSO and explicitly send it to the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM