-
Cookies!
Hi.
Do anybody knows how the cookies in Windows Internet Explorer works?
I am trying to make a program that will help me log in / log out of my frequent websites at a click of the button.
I have tried cutting the "website[1].txt" from the "C:\Documents and Settings\UserName\Cookie" and pasting it back but it did not work. I am unable to find what other changes Windows Internet Explorer make. I tried searching for "webuserrname" in the registry but did not find any.
Thanks in advance.
-
Cookies are given to the client from the webserver. You cant just generate your own cookie, you need to receive one from the webserver with a request. The reason for this is that many (not all) servers invalidate the cookies after a certain amount of time. This is done for security reasons, and therefore you need to get a new cookie from the server.
-
You can use the InternetSetCookie() function to set a cookie value that will be picked up by Internet Explorer (but not other browsers). However, as mentioned by bithub, you typically need to logon to get the correct cookie value anyway.
This code seems to work to logon to cboard. You can get the correct value for bbuserid and bbpassword from inside the IE cookie file or from Firefox.
Code:
#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")
int main (void)
{
InternetSetCookie(TEXT("http://cboard.cprogramming.com"), TEXT("bbuserid"),
TEXT("1001; expires = Sat, 01-Jan-2005 00:00:00 GMT"));
InternetSetCookie(TEXT("http://cboard.cprogramming.com"), TEXT("bbpassword"),
TEXT("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; expires = Sat, 01-Jan-2005 00:00:00 GMT"));
return 0;
}