1

i'm making a adwords-like to my clients websites only, and i wan't to put the cookies to save the information to all domains (and not just domain mydomain.com or subdomains .mydomain.com, i mean all).

Code Sample:
setcookie('var_name', 'var_value', null, "/", '.mydomain.com' );

Can anybody help me?
Thanks

cusspvz
  • 5,143
  • 7
  • 30
  • 45
  • What do you mean by all domains? What are “all domains”? – Gumbo Sep 09 '10 at 12:01
  • possible duplicate of [Cross domains sessions - shared shopping cart cross domains](http://stackoverflow.com/questions/2956214/cross-domains-sessions-shared-shopping-cart-cross-domains) – Pekka Sep 09 '10 at 12:02
  • Also related: http://stackoverflow.com/questions/3342140/cross-domain-cookies – Pekka Sep 09 '10 at 12:03
  • Short answer: This is not trivial to implement. If you do not control the client's domain, it will probably be impossible. – Pekka Sep 09 '10 at 12:03
  • @Pekka but what do i put in domain option to fit to all domains? – cusspvz Sep 09 '10 at 12:04
  • @Gumbo for example, my code is in `microdual.com`, and i have a client with ads in `mydomain.com`, `domain.com`, etc. I want to put the cookie domain setting to 'multi-domain' so i can save the session... – cusspvz Sep 09 '10 at 12:05
  • @Pekka this questions is like a sub-question of my last question. I can't find a solution... :/ – cusspvz Sep 09 '10 at 12:07
  • @CuSS Cookies across totally different domains (that are not subdomains of the same domain) are not trivial to implement. It can't be fixed by changing an option in `setcookie()`, you'll need to do a lot more than that. Read through the links. – Pekka Sep 09 '10 at 12:07
  • @Pekka so how google adwords save the session information on multi-domains? – cusspvz Sep 09 '10 at 12:08
  • @CuSS I don't know where and how AdWords sets cookies... Maybe they can set cookies for their own domain because the script gets fetched from google.com? I don't know exactly right now. – Pekka Sep 09 '10 at 12:11
  • @Pekka hm... my problem is the same of the older question, if ajax is loading from an external source, it should do cookies for that domain, and it doesn't... – cusspvz Sep 09 '10 at 12:15
  • @CuSS as I said in the other answer, you can't do an Ajax request from an external source anyway. Have you tried? The response will always be empty. You need a different solution to what you want to do. Maybe worth a separate quetion. – Pekka Sep 09 '10 at 12:16
  • @Pekka i've tryed, it was allways empty, but i've found a solution, see my answer here http://stackoverflow.com/questions/3136140/cors-not-working-on-chrome/3600086#3600086 – cusspvz Sep 09 '10 at 12:22
  • @cuSS ah, you've done much more there than I thought. I stand corrected. But as I also said in the other answer, you could carry the session across in a GET parameter instead of relying on a cookie :) (That won't give you the session from the other server itself, though.) – Pekka Sep 09 '10 at 12:27

3 Answers3

4

You cannot set a cookie for a foreign domain. That would be a serious security flaw. Just think of how easy attacks like session fixation would be.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
2

You can use an iframe to share and display the same information for a specific user on many pages. That's how Google Adsense and many other advertising solution work.

2ndkauboy
  • 9,302
  • 3
  • 31
  • 65
  • i have to use this... my idea was to automaticly detect the site, get keywords from site, contact server, see what type of ads it would need, and automaticly put them on the page... see http://search.microdual.com/ – cusspvz Sep 09 '10 at 12:34
1

Most tracking systems of this type work by embedding an image or some other object into participating sites which is served from your domain. At this point you can issue cookies from the single domain that you do control, and track the users by watching the referral data on your web requests.

Since the object is served from your domain, there's no need for the cross-domain cookies that you're asking for, which is fortunate because they're not possible to do.

Spudley
  • 166,037
  • 39
  • 233
  • 307