By default, you cannot set a cross-domain cookie. I believe you can configure the P3P file (s) to include it. http://p3ptoolbox.org/guide/section4.shtml#IVd I myself did not do this, so I donβt know how many of them are implemented in browsers or even work like that.
Virb looks simple using JavaScript. It has an AJAX library that makes a JSON-P request to the virb server if no session cookie is set. (first Firefox download you can see this in Firebug). The JSON response simply allows the page to know whether the user is registered or not, and updates the parts of the page that should reflect the status of the user.
So what happens, the page inserts some JS from virb.com. Since the virb.com domain, the cookie set on virb.com is sent to the server. The server then responds to the cookie result to an external site.
In the case of virb, which would not work properly without JS, I think this is a good option. However, you can do the same with HTTP redirects.
If the HTTP host is not the primary domain (example.com):
if (!$_COOKIE['sessionid'] && $_SERVER['HTTP_HOST'] != 'example.com') {
Set a cookie on the main site and send the user back to the external domain (domain.com), passing the session identifier to Location.
header('Location: http://domain.com.com?sessid='.urlencode($_COOKIE['sessionid']));
The last bit is to redirect back to the page you were on, now that you have the same session.
setCookie(...); // sessid in $_GET['sessid'] header('Location: http://domain.com/');
Please note that in fact you can send the page that you will now return to example.com in the first step so that you can redirect it back later.
Since you just use headers (you do not need to output the content), and in most cases HTTP / 1.1, so you will be in the same TCP socket, I think it is quite efficient and will be more supported than the JavaScript version.
Edit: Remember to set a cookie when you return to the external domain.
The final step is optional, but it does not support sessid in the URL. This is more a security issue than persisting in HTTP headers.