I'm pretty sure that this will only work in your situation with subdomains or paths.
You cannot set (or read) a cookie for a foreign domain. This would be a big security problem.
So you only may set a cooky for the same domain and same path. Additionally for parent directories or the "root" domain. So it is possible to set a cookie from
www.domain.com for domain.com which can be read from domain.com.
The IE has a small glitch if you do not set the cookie domain: If you then set a cookie to domain.com you cannot override it from
www.domain.com. Let's assume a simple auto-login script. Somebody logs in using domain.com. Later he comes back using
www.domain.com. He is automatically logged in but cannot logout as long as he tries it on the domain
www.domain.com! So setting the cookie domain is generally a good practice.
If you realy want to set a cookie for another domain there are some possibilities. You could insert an image or an iframe within your page where you transfer the information via query string. This image or page in the iframe is located on the other domain and sets the cookie.
Because of security issues the newer browsers standard security settings prohibit setting cookies this way on domains not equal to the main site or the main frameset. This is for instance a problem for the banner ad agencies.
So my only idea is to forward to the a script on the second domain which sets the cookie. This script forwards back to the initial script. I havn't tried that yet, but it should work.