I'm a php developer but not experience in tra开发者_运维技巧ining now and got a task that if someone open website from firefox then cookie must be saved in chrome, opera and other browsers too.
While, you can't share directly cookies across browsers, you can use Flash to store the value in a SharedObject and read it. As this is handled by Flash player, it will work on all browsers.
This will work. It's done in Flex:
//Write the SharedObject
var mySharedObject:SharedObject=SharedObject.getLocal("mySharedObject", "/");
mySharedObject.data.role = role;
mySharedObject.flush();
//Read it when needed
var mySharedObject:SharedObject=SharedObject.getLocal("mySharedObject", "/");
role = mySharedObject.data.role;
If you need it as a cookie, you can also call javascript from Flex to read the SharedObject and write the value in a cookie:
//Write it as a cookie
ExternalInterface.call("document.insertScript = function ()" +
"{ " +
"if (document.snw_setCookie==null)" +
"{" +
"snw_setCookie = function (name, value, minutes)" +
"{" +
"if (minutes) {"+
"var date = new Date();"+
"date.setTime(date.getTime()+(minutes*60*1000));"+
"var expires = '; expires='+date.toGMTString();"+
"}" +
"else var expires = '';"+
"document.cookie = name+'='+value+expires+'; path=/; domain=.example.com;';" +
"}" +
"}" +
"}");
This way you can have the same cookie in all browsers. Let me know if you have trouble with this.
You are not able to set a cross browser cookies through PHP.
There are some tricks though, but it will use flash instead. See this link for more information.
精彩评论