tags:

views:

214

answers:

3

Hello, I want to create a c++ application that works together with a website. In order to keep the application synchronized with the website I want to be able to read some cookies from the user's default browser. Is there any way to do this?

+1  A: 

Firefox stores all its cookies in cookies.txt: http://www.velocityreviews.com/forums/t10844-cookies-in-firefox.html

For the "default browser", you're going to have to write custom code for the number of different browsers out there, but it's certainly not possible. See: http://www.aboutcookies.org/Default.aspx?page=2#ie7 for a start, and get googling!

Stefan Mai
+2  A: 

Not in the general sense - there's no real defined format for cookie storage, so each browser is free to keep the cookie database wherever, and in whatever style, it prefers.

You could implement cookie reading functions for the mainstream browsers (IE, Firefox), but that would leave some people out. It would also be non-robust - what happens when the user clears their cookie cache, or uses more than one browser?

If you want to keep your application synchronised with a website, I'd recommend that you have it call directly into web services (RESTful, etc) on that site, with a username/identifier your application users configure. This way, you're not tied to an arbitrary 3rd party that is, at best, only "maybe" right.

Adam Wright
+1  A: 

Yes, fairly trivial. Define a webservice http://example.com/capturecookie?tracking-guid. It returns the cookie sent the last time for that GUID. From you application, pick a random guid. Call that webservice with your random GUID first in the default browser (See other S.O. topics for that) and then with the same GUID from inside your application. The second time, you'll get back the cookies from the first.

Note that the exact notion of "cookies of a webbrowser" is necessarily imprecise. For instance, my default webbrowser (Opera) is set to drop all cookies when it exists, except cookies from whitelisted sites. So whether example.com has cookies depends a lot on whether Opera is running.

MSalters