views:

483

answers:

3

Please, I would like to set cookies for my browser by my script running at my domain.. but I want to set cookies from another domain.

For example, I would like to set cookies that twitter.com sends me (when I would visit by browser), but I don't want to visit their page for the first time. Only when I visit their page after running my script, I want that their cookie is already set. Is it possible at all?

I thought, that changing the domain variable for document.cookie is doing the trick, but it doesn't work.. the twitter doesn't see any cookie being set.

+2  A: 

You can't.

David Dorward
+3  A: 

No you can't obviously. Being able to control cookies from domains other than the one your website/webapplication runs on, would be a tremendous security risk. Because being able to set, would also mean being able to read.

Cloud
Perfect.. I understand now. Thank you :)
neon
+1  A: 

You can, but it requires some hacks and can't be done in javascript alone.

Open up firefox and grab your "auth_token" cookie from twitter.com

If you have access to a web server and can config it to accept all host headers.

Makeup a fake subdomain and add it to your hosts file like:

127.0.0.1 xxxxxxx.twitter.com

from that server set a cookie named "auth_token" with *.twitter.com as the domain.

This would work for twitter because their auth_cookie is set to expire in 20 years.

Chad Grant
Very interesting.. haven't seen that anywhere else. It seems like you have good experiences with working with twitter, right? I am also dealing with automatic login script, but the authentization_token is giving me hard times.
neon
I think I am the only person on the planet that thinks twitter is dumb. but I have used this method in some not so legal ways ;)
Chad Grant