Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create cookie with external domain?

I have created a javascript script which people can asynchronously load to their websites by pasting a small code like Facebook, Google does when we want to integrate their javascript SDK. From my script I want to create a cookie with my domain as Facebook , Google does with their domain. I'm trying to create cookie with domain by that little framework given by Mozilla.

docCookies.setItem('cookie1', 'some value',Infinity, '/', '.example.com');

Where '.example.com' is my domain name where I have that script which people loading to their website. I'm trying to create that cookie in any domain which load my script. But it's not working, no cookies have been set so far. How I can create a cookie with my domain from that script to other domain?

[Sorry for my bad English.]

like image 735
Mokhlesur Rahman Avatar asked Nov 16 '14 08:11

Mokhlesur Rahman


1 Answers

This might be the explanation:

If I understand you correctly, your script is loaded from www.example.com, but used by sites on other domains, let's say www.someotherdomain.com.

If you create a cookie and try to use this cookie in a request from www.someotherdomain.com to www.example.com, the browser will consider this a third-party cookie. The cookie is a third-party cookie becuase the domain you're at (www.someotherdomain.com) differs from the domain the request is sent to (www.example.com).

Several browsers block third-party cookies, and the cookie is therefore not included in the request to www.example.com.

There's no way you can stop the browsers blocking third-party cookies, you'll have to look at alternative techniques.

like image 175
Per Kristian Avatar answered Sep 20 '22 17:09

Per Kristian