Reading Cookie from Other Website with Different Domain

By W3C rule, a web browser is not permitted to read cookies from different site with different domains. So how do we beat the challenge of reading cookies from other 3rd party site when let's say you were task to integrate it in your site and there are some needed parameters that are stored on 3rd party cookies which you need to read.

You'll need your Network Admin guy for this task or if you have access to CPanel or similar UI which allows your to assign subdomain alias (CNAME).

First, create a subdomain definition from your own domain, let's say var.mydomain.com. Then add the alias for the target domain/subdomain (e.g. www.analytics.com) to equate/resolve to your subdomain (in this case, var.mydomain.com). Just to avoid legality issues, you may ask permission from the 3rd party site that you want to create alias for their domain for purpose of integrating and allowing your site to read their cookie .

Now here's the magic, when you invoke the 3rd party site from within your site, e.g. from a particular URL (http://www.analytics.com/trackvisit.php), and that site started writing cookie. That cookie will be saved under var.mydomain.com which is your defined subdomain. Any subdomain under your domain allows browser to read that cookie from your site.

With this technique, you can also implement any session sharing imaginable, e.g. Single login from different disperse site, provided you owned and have access to the site's source code.

No comments:

Post a Comment