user863317
user863317

Reputation:

Can anyone know how to setting cross web browser cookie

I'm a php developer but not experience in training now and got a task that if someone open website from firefox then cookie must be saved in chrome, opera and other browsers too.

Upvotes: 1

Views: 255

Answers (2)

Zesty
Zesty

Reputation: 3001

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.

Upvotes: 1

Devator
Devator

Reputation: 3904

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.

Upvotes: 1

Related Questions