0

I have a Firefox extension that I am creating with the Jetpack builder.

What happens, is I set a cookie on user login on a page (PHP). The cookie's contents is a special key used to identify the user, this key can get certain info on the user in order for the plugin to work.

I make an XMLHttpRequest from the Firefox plugin to a php page on the same server as the login page. This page must read the cookie, and retrieve data based on that.

The problem is, that the cookie is not being read by the php page. This whole process works in Chrome, but not in FF. The problem should not be cross-domain, as the PHP page accessing the cookie is on the same domain as the Login PHP setting the cookie.

Please help... Thanks! :)

P.S. Here is my XMLHttpRequest:

function getData() {
                client = new XMLHttpRequest();
                try{
                    //SHOULD I INCLUDE THE CODE IN 'TRY' IN HERE?
                    client.open('GET','https://www.istyla.com/Popup/themes.php');                   
                } catch (e){
                    alert( "error while opening " + e.message );
                }

                client.onreadystatechange = function(){
                    if (client.readyState ==4){
                            user_data = client.responseText;
                            if(document.domain == "facebook.com"     || document.domain == "www.facebook.com") {
                                addCSS(user_data);
                            }
                    }
                }

                client.send(null);
} getData();
4

1 に答える 1

0

送信する前に、このコードをリクエストに追加してみてください ( https://addons.mozilla.org/sl/firefox/files/browse/134669/file/modules/sendtophone.js#L173からコピー)。

// To send correctly cookies.
// Force the request to include cookies even though this chrome code
// is seen as a third-party, so the server knows the user for which we are
// requesting favorites (or anything else user-specific in the future).
// This only works in Firefox 3.6; in Firefox 3.5 the request will instead
// fail to send cookies if the user has disabled third-party cookies.
try {
  req.channel.QueryInterface(Ci.nsIHttpChannelInternal).
  forceAllowThirdPartyCookie = true;
}
catch(ex) { /* user is using Firefox 3.5 */ }
于 2012-06-03T21:02:30.413 に答える